Knowing type of generic in Java

后端 未结 7 1145
醉话见心
醉话见心 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:56

    if (object instanceof String)
       System.out.println("object is a string");
    

提交回复
热议问题