对于我,这不能用Scala 2.7.7.final或2.8.0.final 编译:
new FileInputStream("test.txt") getChannel transferTo(
0, Long.MaxValue, new FileOutputStream("test-copy.txt") getChannel)
Run Code Online (Sandbox Code Playgroud)
这对我来说使用Scala 2.7.7.final和2.8.0.final进行编译:
new FileInputStream("test.txt") getChannel() transferTo(
0, Long.MaxValue, new FileOutputStream("test-copy.txt") getChannel)
Run Code Online (Sandbox Code Playgroud)
为什么我需要做getChannel()
而不仅仅是getChannel
在这里?
一般规则是编译器解释字符串
new FileInputStream("test.txt") getChannel transferTo(...)
Run Code Online (Sandbox Code Playgroud)
如
object method parameter method parameter method parameter
Run Code Online (Sandbox Code Playgroud)
所以在你的情况下,这意味着
new FileInputStream("test.txt") // object
getChannel // method
transferTo(...) // parameter
Run Code Online (Sandbox Code Playgroud)
所以编译器尝试调用transferTo
自由函数,因此它可以将其结果作为参数传递给getChannel.当你添加括号时,你会得到
new FileInputStream("test.txt") getChannel() transferTo(...)
new FileInputStream("test.txt") // object
getChannel // method
() // parameter (empty parameter list)
transferTo // method
(...) // parameter
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
924 次 |
最近记录: |