• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to extract generic type information from a typed collection?  RSS feed

 
Arnold Reuser
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to extract the generic type parameter class
String from the declared variable strings stated below.
Could anyone provide me a best practice on how to retrieve
this type of runtime information?

 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't any way to do that - the info doesn't exist at runtime.
 
Arnold Reuser
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response. It is puzzling me why this is not the case.
Can you provide a solid reason?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arnold Reuser:
Thanks for your response. It is puzzling me why this is not the case.
Can you provide a solid reason?


In short: backward compatibility.

A longer explanation can be found at http://today.java.net/pub/a/today/2003/12/02/explorations.html under "Erasure".
 
Arnold Reuser
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting read!
Based on this article, and to gain a deeper understanding
of how its organized, I wrote the code stated below.
It will help you extract the generic type information from a typed property
of a bean.


[ January 01, 2008: Message edited by: Arnold Reuser ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!