| Author |
how to determine the real type of a generic property?
|
Geronimo M. Hernandez
Greenhorn
Joined: Mar 16, 2009
Posts: 7
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
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:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Geronimo M. Hernandez
Greenhorn
Joined: Mar 16, 2009
Posts: 7
|
|
Thank you for your support!
I will implement that getType().
|
 |
 |
|
|
subject: how to determine the real type of a generic property?
|
|
|