I’m writing a Scala class that implements (wraps) a java.util.List, i.e.:
class MyList(backingList: java.util.List) extends java.util.List
The latter has a method toArray with a Java signature like this:
<T> T[] toArray(T[] a)
Naively, I wrote this as:
def toArray[T](a: Array[T]) = backingList toArray a
but the compiler complains that the call to toArray on backingList expects an Array[? with java.lang.Object].
I think I’ve tried every possible variation over things like Array[_ >: T with Object] (which the compiler kindly suggests), but no luck. Any suggestions?
This also works: