Supposed I have a Java API like below:
public class JavaApi<T> {
public void foo(T[] data) {
...
}
}
And I'd like to call it from Scala with the following class:
class Caller[T] {
val javaApi = new JavaApi[T]()
def callApi(data: Array[T]) = javaApi.foo(data)
}
On compile, I get the following:
type mismatch;
found : Array[T]
required: Array[T with Object]
Note: T >: T with Object, but class Array is invariant in type T.
You may with to investigate a wildcard type such as `_ >: T with Object`. (SLS 3.2.10)
def callApi(data: Array[T]) = javaApi.foo(data)