This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to obtain parameter of parametrized class?

 
Tymur Porkuyan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to obtain a reference to a class which is a parameter of a generic class? I tried this, but it didn't work:



Is there any other way or it's impossible?
[ February 07, 2006: Message edited by: Timur Porkuyan ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have an instance of the parameter type, then you can call getClass() on that instance.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by marc weber:
If you have an instance of the parameter type, then you can call getClass() on that instance.


That's not exactly the same, as the instance could also be of a subclass.

And to answer the original question: no, this is not possible in Java.
 
Tymur Porkuyan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:
... That's not exactly the same, as the instance could also be of a subclass...

Good point.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic