|
|
Re: Type variables
|
Posted: Mar 3, 2006 2:27 PM
|
|
The only way this can be done is if the class of T is known. Then, using a newInstance() on the class of T will get you a T object created using a no-args constructor. It is relatively easy to use reflection (java.lang.reflect.Constructor) to get a Constructor object of the known class of T with specified parametere types.
But why do you need to know the class of T when using parametrized classes? The whole point of the parametrized classes is that T is unknown until runtime! Hence, the parametrized classes can work with any type.
|
|