Forum Stats

  • 3,760,221 Users
  • 2,251,664 Discussions
  • 7,871,026 Comments

Discussions

Generic class

843793
843793 Member Posts: 41,732 Green Ribbon
edited Apr 8, 2010 10:23AM in Generics
Hi,

I have this following class with a get method:
public class Dao {
    <T> public T get(Class<T> clazz, long id) {
        ...
    }
} 
Now, what I want is to create a dao that takes a specific model class. I don't want it's users to have to send the class as argument to the get method, and would like the code to look like this:
public class SpecificDao<T> {
    private Dao dao;
    public T get(long id) {
        return dao.get(/* ??? */, id);
    }
}
So my problem is, what should I use instead of /* ??? */. I can't write T.class since no such thing exists. But I need the Class instance of T. Any ideas on how to retrieve it?

Thanks,

/U

Comments

This discussion has been closed.