I understand that due to the way java implements generic typing its impossible to instantiate new generic arrays inside generic methods. on top of this all generic collection in java are of the type "Object" at runtime.
A big use of generic types is having functions that process arrays of various types that are implemented as one generic function rather than using Polymorphism,this reduces redundancy.
for example I would like to have code such as this:
public static <V> V[] operateOnArray(V[] sourceArr) {
V[] returnArr = new V[sourceArr.length];
for (int i = 0; i < sourceArr.length ; i++) {
returnArr[i] = utils.process(member);
}
return returnArr;
}
However within this code V[] cannot be instantiated directly... Is this still possible to make a function that returns a new generic array, or is there a sufficiently elegant workaround?