For a generic class, for example, List<T>, how can I get the "Class" object ?For raw type List, I can get Class<List> by calling List.class; however, I cannot call List<T>.class to get Class<List<T>> object.The motivation that I want to get Class<List<T>> is for the follow function call.List<T> list = create(Class<List<T>> c);
thanks for your help, in advance .

解决方案 »

  1.   

    if the list is not empty and the Class<T> is a POJO,your can test the type of any element in the list 
    if not ,or the Class<T> is just a abstract class,your have to test every element to get its type
    does anyone have a better solution?
      

  2.   

    create(Class<List<T>> c);
    这个方法接收一个普通的Class对象就可以了,返回一个List可以直接赋值给List<T> list
      

  3.   


    If I call "create" function with List.class as argument, compiler will give me warning .....(saying something about raw type ....)
      

  4.   

    你该看看泛型擦除,运行时是无法得到类型参数的信息的。而且,List类只有一个,不是说有多少种类型参数就会有多少个List类,所以也没有List<T>.class这种东西,只能是List.class。