aspose file tools*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Type of Generic" Watch "Type of Generic" New topic
Author

Type of Generic

Mic Popolin
Greenhorn

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

class Boo<E>{
execute(){
//How can I get the Class of E ???
}
}

or

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

Thank's


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

Joined: Aug 17, 2001
Posts: 171
    
    1
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.

Geoffrey


Sun Certified Programmer for the Java 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Type of Generic