Knowing type of generic in Java

后端 未结 7 1137
醉话见心
醉话见心 2020-12-03 16:17

I have a generic class, says :

MyClass

Inside a method of this class, I would like to test the type of T, for example :

         


        
7条回答
  •  被撕碎了的回忆
    2020-12-03 16:46

    Additionally to cletus one exception I've mine: super type tokens. The super type token will preserve the type information.

    new Type>() {}

    The type information can be retrieved with Class.getGenericSuperClass.

提交回复
热议问题