Error with default argument in Source.getLines (Scala 2.8.0 RC1)
assuming I running Scala 2.8.0 RC1, the following scala code should print out the content of the file "c:/hello.txt"
for ( line<-Source.fromPath( "c:/hello.txt" ).getLines )
println( line )
However, when I run it, I get the following error
<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:/he开发者_开发技巧llo.scala").getLines
From what I understand, Scala should use the default argument "compat.Platform.EOL" for "getLines". I am wondering if I did wrong or is it a bug in scala 2.8
Thanks
Write getLines()
instead, so that the default gets used.
As Daniel says, you need to put parentheses after the method name for this to compile. If a method definition includes parentheses, when you call it you must also use parentheses. Presumably this still holds if all the arguments to the method have default values (as is the case here).
精彩评论