Source.getLines(Scala 2.8.0 RC1)中的默认参数出错

Source.getLines(Scala 2.8.0 RC1)中的默认参数出错,scala,scala-2.8,Scala,Scala 2.8,假设我运行的是Scala 2.8.0 RC1,下面的Scala代码应该打印出文件“c:/hello.txt”的内容 for(lineWritegetLines(),这样就可以使用默认值。正如Daniel所说,您需要在方法名称后加上括号,以便编译。如果方法定义包含括号,则在调用时也必须使用括号。如果该方法的所有参数都有默认值(如此处所示),这一点可能仍然有效 for ( line<-Source.fromPath( "c:/hello.txt" ).getLines )

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


for(lineWrite
getLines()
,这样就可以使用默认值。

正如Daniel所说,您需要在方法名称后加上括号,以便编译。如果方法定义包含括号,则在调用时也必须使用括号。如果该方法的所有参数都有默认值(如此处所示),这一点可能仍然有效

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