I have a method, which I cannot change, that takes a T[] array.
I need to “toString()” element [i] of array, not knowing the type of T in advance.
For all objects, I could call toString() but T[] could be an array of primitives and this does not make sense:
int i = 0;
i.toString(); // nonsense
What can I do?
In response to:
Generic types cannot be primitives, which guarantees that the array will always be an array of objects. Since every object extends
Objectit will have atoStringmethod.