Source.getLines 中的默认参数错误 (Scala 2.8.0 RC1)
假设我运行 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 中的一个错误
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请改为编写
getLines()
,以便使用默认值。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).