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

发布于 2024-08-31 00:49:25 字数 619 浏览 5 评论 0原文

假设我运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最美的太阳 2024-09-07 00:49:25

请改为编写 getLines(),以便使用默认值。

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

只是在用心讲痛 2024-09-07 00:49:25

正如丹尼尔所说,您需要在方法名称后面加上括号才能编译。如果方法定义包含括号,则调用它时也必须使用括号。如果该方法的所有参数都有默认值(就像这里的情况),这可能仍然成立。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文