1

Why does this work

public E a;
public MySortedArray(E asdf){
    a = asdf;
}

and this doesn't?

public E[] a;
public MySortedArray(E[] asdf){
    a = asdf;
}

How can I achieve the second when let's say I do

    MySortedArray<Integer> test = new MySortedArray<>(integersArray);
MayTheSchwartzBeWithYou
  • 1,181
  • 1
  • 16
  • 32

1 Answers1

2

Java does support boxing int to Integer, but not boxing arrays of those numeric types, e.g. it won't box int[] to Integer[].

You must convert the int[] to an Integer[] yourself before passing it to your MySortedArray<Integer> instance.

rgettman
  • 176,041
  • 30
  • 275
  • 357