我在scala程序中调用Java枚举的方法values
,当我尝试获取该数组时,如果我不明确地调用apply,它就不会编译。
MY_JAVA_ENUM.values(0) //COMPILATION ERROR too many arguments for values
My_JAVA_ENUM.values.apply(0) //WORKS
我使用Scala 2.9,为什么会这样?
答案 0 :(得分:2)
在工作案例中你可以免费获得parens。
scala> def f() = 1 to 10 toArray
warning: there were 1 feature warning(s); re-run with -feature for details
f: ()Array[Int]
scala> f(4)
<console>:9: error: too many arguments for method f: ()Array[Int]
f(4)
^
scala> f.size
res1: Int = 10
scala> f.apply(4)
res2: Int = 5
scala> f().apply(4)
res3: Int = 5
scala> Thread.State.values()(1)
res4: Thread.State = RUNNABLE