How can i create a generic array in java, the right way?
T[] buffer = (T[]) new Object[maxSize];
Would it better to create a new generic collection and then cast it?
How can i create a generic array in java, the right way?
T[] buffer = (T[]) new Object[maxSize];
Would it better to create a new generic collection and then cast it?
You can use newInstance method that offer Array class, but it require the Class of type.
The only solution that i see is create a Object array and then cast it to T[]
T[] array = (T[])Array.newInstance(Object.class, size);