• 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 get generic type?

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

This is the class declaration -

I want to get the T class.

In case that this class extended by another class its done by:


Any idea how its done for this?


need to get ItemTO.class

Thank you
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Somebody else asked the same question very recently: here. It is not possible by any simple means, but have a look at the other thread which might give some information.
 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure its not possible.
He has another question.

Thank you
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

avihai marchiano wrote:I am not sure its not possible.
He has another question.

Thank you



The main difference between the other question and your question, is that the other question actually doesn't know the type of elements in the collection that is passed into the method.

With your question, you actually know that it is a Criteria<ItemTO> instance, so you know it is the ItemTO.class object that you want. And can just specify it iin source. No need to search based on the Criteria object.


Now, if you don't want to define the ItemTO.class in source, but want to search based on the Criteria<ItemTO> instance, then you have the same issue as the other question.

Henry
 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can i define the template type through using like this:
Criteria<ItemTO> criteria=new Criteria<ItemTO>();

So, T in the following declaration -
Criteria<T>

T will be ItemTO

I dont want to set the type by extend it.

Thank you
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java Generic is of a type erasure. this is done for backwards compatibility. this means that you won't be able to code it to know the class of T during runtime in your Generic class. not sure this is related what you are looking for, but hope this will help a bit.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic