The method defined in the Java API:
interface Collection<T> {
<X> X[] toArray(X[] a);
}
I attempt 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've left out the other methods in the interface for clarity. The compiler complains with:
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 do I successfully override the toArray(..) method?