Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:/hello.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

like image 656
defoo Avatar asked Jan 22 '23 04:01

defoo


2 Answers

Write getLines() instead, so that the default gets used.

like image 100
Daniel C. Sobral Avatar answered Mar 23 '23 02:03

Daniel C. Sobral


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).

like image 25
Ben Lings Avatar answered Mar 23 '23 02:03

Ben Lings