我不明白为什么下面的代码不能编译:
class Abc
{
def b (x : String) = x + "abc"
def a (y : String) =
{
val ls : List[String] = y.lines toList
b (ls.head)
}
}
Run Code Online (Sandbox Code Playgroud)
Main.scala:8:错误:类型不匹配; 发现:java.lang.String required:Int b(ls.head)
当我将"y.lines toList"更改为
y.lines.toList
Run Code Online (Sandbox Code Playgroud)
甚至到
y.lines toList;
Run Code Online (Sandbox Code Playgroud)
它确实编译.
也许编译器理解它就像
(y.lines).toList(b (ls.head))
Run Code Online (Sandbox Code Playgroud)
或类似的东西,但我仍然不明白规则.