How to get generic's class

前端 未结 3 1505
南方客
南方客 2020-12-19 18:52
Class Model{

   private T t;

   .....


   private void someMethod(){
       //now t is null
       Class c = t.getClass();
   } 

   .....

}
         


        
3条回答
  •  情歌与酒
    2020-12-19 19:22

    You can do this with reflection:

    Field f = this.getClass().getField("t");
    Class tc = f.getType();
    

提交回复
热议问题