1

I run the method

MyObject[] myObjects = append(MyObject.class, myObjectCurrentArray, append1, append2, append3);

public static final <T> T [] append(Class T, T[] array, T... appendThese){
    T[] newArray = new Object[array.length + appendThese.length];
    //put T[] array and T...appendThese into newArray
    return newArray;
}

This throws the Exception

java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lxxx.MyObject;

How should I fix this?

theAnonymous
  • 1,701
  • 2
  • 28
  • 62
  • 1
    I vote to reopen this question, as I don't believe the "duplicate question" addresses OP's issue, especially because OP is looking to concatenate to an already-existing array with elements of the same type. I have an explicit solution to solve their problem. – Jacob G. Nov 05 '17 at 06:52

0 Answers0