To create array of generic, I have seen below recommendation in many websites including this one, too. However, I wonder why we do not use directly the generic class in array creation. What is the reason to push us to not use below array creation method?
What currently is used
public class X<T> {
private Y<T> tTypeClass = null;
public T[] Array() {
T[] array = (T[]) Array.newInstance(tTypeClass.getObject().getClass(),4);
}
}
Why we do not use
public class X<T> {
public T[] arrayCreation() {
T[] array = (T[]) Array.newInstance(this.getClass(),4);
}
}