2007-03-25

Java Generics: Instantiating Objects Of Type Parameter Without Passing Class Literal To Instance

Cause generics in Java 1.5 and 1.6 are implemented using erasure, in most cases you can not get class object for type parameter, which means that in your generic classes you can not instantiate objects of type parameters. Usually this is solved by special setup of generic class instance (by passing class literals to methods which instantiate objects of type parameter class) but it does not look too god. Fortunately, you can avoid such ugly code in some situations and make generic class smart enough to handle it by itself. More...

No comments: