• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to determine the real type of a generic property?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your support!

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