The problem is that, at run time, the JVM does not know which class actually means T (this information is not stored at run time, which means "type wiping"). Therefore, the JVM just sees that you want to build a new T , but you donβt know which constructor to actually call, so it is not allowed.
There are workarounds, but they will not work as you suggest.
why does the compiler not assume that T is an object and build it ??
Well, of course, the runtime might just create an instance of java.lang.Object for you, but that would not help, since you really wanted T
sleske
source share