我正在尝试在 Scala 中编译简单的 helloworld,并得到错误“scala: value capitalize is not a member of Char” 为什么编译器认为 newW 是 Char?
val dict = Map(
"hello" -> "olleh",
"world" -> "dlrow"
)
def translate(input: String): String = {
input.split( """\s+""").map(w => dict.getOrElse(w.toLowerCase, w).map(newW =>
(if (w(0).isUpper) newW.capitalize else newW))
).mkString(" ")
}