How to convert Scala Array[Int] to Java Integer[]? It seems that the default is to convert int to int[] and that's not a proper argument for method defined as
public static <T extends Comparable<? super T>> T[] merge(T[] xs)
Compiling fails with the following error
type mismatch;
found : Array[Int]
required: Array[? with Object]
Note: Int >: ? with Object, but class Array is invariant in type T.
You may wish to investigate a wildcard type such as `_ >: ? with Object`. (SLS 3.2.10)
val res = SimpleSort.merge(xs)
^
Maybe with:
val javaArray: Array[java.lang.Integer] = scalaArray map java.lang.Integer.valueOf
AFAIK, it is not a good practice in java to manipulate array of objects, you should use Lists instead. BTW, your merge method will have trouble instantiating the array of T.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With