Method defined in the Java API:
interface Collection<T> {
<X> X[] toArray(X[] a);
}
I am trying to do something like this in Scala:
class SCollection[T] extends Collection[T] {
val queue = new LinkedBlockingQueue[T]
def toArray[X](a: Array[X]) : Array[X] = queue.toArray(a)
}
I left the other methods in the interface for clarity. The compiler complains:
overloaded method value toArray with alternatives:
[T](x$1: Array[T with java.lang.Object])Array[T with java.lang.Object] <and>
()Array[java.lang.Object]
cannot be applied to (Array[X])
def toArray[X](a: Array[X]) : Array[X] = queue.toArray(a)
^
How to successfully override the toArray (..) method?
source
share