【发布时间】:2015-03-05 19:48:17
【问题描述】:
我有这个简单的代码:
import java.util
import scala.collection.JavaConversions._
def f(x: util.List[Int]): Array[Int] = {
x.toArray[Int]
}
error: missing arguments for method toArray in trait List 失败
但是toArray 的源代码如下:
trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] {
...
def toArray[B >: A : ClassTag]: Array[B] = {
if (isTraversableAgain) {
val result = new Array[B](size)
copyToArray(result, 0)
result
}
else toBuffer.toArray
}
显然没有遗漏的论点。
1) 这怎么可能?有简单的解决方法吗?还是我错过了什么?
2) 错误消息以follow this method with '_' if you want to treat it as a partially applied function 继续。你不觉得这是一个愚蠢的提议吗?我已经声明了返回值,所以部分应用的函数不能工作。编译器应该会看到它。
【问题讨论】:
标签: java scala arraylist partial-application toarray