This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android forum!
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
It is sorta covered in the JavaRanch Style Guide.
subject: Type of Generic
Similar Threads
dout in genric coll help
Doubt in generic method
Cannot understand enum class syntax
generics and inner classes
Inner Classes Question