Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to determine the real type of a generic property?

 
Geronimo M. Hernandez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a concrete class, which is a child of a generic class. That generic class is a bean with a generic propery (I simplified the classes for sample use):


The concrete class looks like


From a beanprocessor I like to determine the type of the "elem" property used at the concrete type "Derived".
How can I figure that out?
Using reflection, the return-type of getElem() is Object.

Any hint is welcome.

regards Gero
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't, because of type erasure. In short, generics are a compile time only mechanism, and all traces of it are removed from the generated byte code.

How I solved this once is by giving the abstract class an abstract method:

Not the most ideal solution though, because you have to override this method in all concrete subclasses. Moreso, the following provides a problem:
 
Geronimo M. Hernandez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your support!

I will implement that getType().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic