I'm allocating an array of T, T extends Number inside a class. I can do it this way:
myClass test = new myClass(Double.class, 20);
Then the constructor itself:
myClass(Class<T> type, size)
{
array = (T[]) Array.newInstance(type, size);
}
I'd like to know if it's possible to do it like this:
myClass(Number n, size)
{
array = (T[]) Array.newInstance(n.getClass(), size);
}
But, I've tried instatiating an object with the second constructor with:
myClass test = new myClass(Double, 15);
And it doesn't work. Am I doing anything wrong, or is it just not possible?