Hi all.
Originally posted by Olivier Croisier:
You cannot be sure that the real type (T) will have a no-arg constructor.
So you cannot write T t = new T() !
Actually, this is not the real reason why you cannot write
new T(). The problem is that generics in
Java is supported by a technique called
type erasure. With this technique, the generic types only exist at compile time. So, the type
T is not really replaced by the real type during runtime. That's why you cannot write
new T().
One thing you could do to help clear out things is to compile the following code and disamssemble it (using javap -c). Note that the disassembled code is the same.
[ July 02, 2007: Message edited by: Leandro Melo ]