This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
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 Soft Skills this week in the Jobs Discussion 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Type of Generic