2 Replies Latest reply: Apr 8, 2010 9:23 AM by 791266 RSS

    Generic class


      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?