4

假设我运行 Scala 2.8.0 RC1,下面的 scala 代码应该打印出文件“c:/hello.txt”的内容

for ( line<-Source.fromPath( "c:/hello.txt" ).getLines )    
        println( line )

但是,当我运行它时,出现以下错误

<console>:10: error: missing arguments for method getLines in class Source;
follow this method with `_' if you want to treat it as a partially applied function
Error occured in an application involving default arguments.
       val it = Source.fromPath("c:/hello.scala").getLines

据我了解,Scala 应该为“getLines”使用默认参数“compat.Platform.EOL”。我想知道我做错了还是 scala 2.8 中的错误

谢谢

4

2 回答 2

5

改写getLines(),以便使用默认值。

于 2010-04-28T19:39:31.607 回答
4

正如丹尼尔所说,您需要在方法名称后加上括号才能编译。如果方法定义包含括号,则在调用它时也必须使用括号。如果方法的所有参数都具有默认值(就像这里的情况),大概这仍然成立。

于 2010-04-28T19:55:03.240 回答