aspose file tools*
The moose likes Java in General and the fly likes How to get generic type? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get generic type?" Watch "How to get generic type?" New topic
Author

How to get generic type?

avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
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
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38881
    
  23
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

Joined: Jan 10, 2007
Posts: 342
I am not sure its not possible.
He has another question.

Thank you
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18846
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
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
luri ron
Ranch Hand

Joined: Dec 11, 2008
Posts: 87
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get generic type?