Error with default argument in Source.getLines (Scala 2.8.0 RC1)

Assuming I'm running Scala 2.8.0 RC1, the following Scala code should print the contents 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 was wrong or is this a bug in Scala 2.8

thanks

+4
source share
2 answers

Write getLines() instead to use it by default.

+5
source

As Daniel says, you need to put parentheses after the method name to compile. If a method definition includes parentheses when you call it, you should also use parentheses. Presumably, this is still true if all the arguments to the method have default values ​​(as is the case here).

+4
source

Source: https://habr.com/ru/post/1308280/


All Articles