File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Type of Generic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Type of Generic" Watch "Type of Generic" New topic

Type of Generic

Mic Popolin

Joined: Jun 24, 2002
Posts: 3
Can I get the type of the generic using package java.lang.reflect?

class Boo<E>{
//How can I get the Class of E ???


class TesteBoo(Boo<?> boo){
//What the type of '?' ???


Popolin.:<br />The Power Of The Dark Side
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
No, you can't. Generics are meaningful only at the source code level. They are not preserved in the class file. So there is no way by reflection to get information about generics from the compiled class.

This is called "erasure." The reason for it is to preserve binary compatibility with older compiled code that does not use generics.


Sun Certified Programmer for the Java 2 Platform
I agree. Here's the link:
subject: Type of Generic
It's not a secret anymore!