This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
posted
0
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.