Test if object is instanceof a parameter type

前端 未结 6 468
再見小時候
再見小時候 2020-12-04 21:02

Is there a way to determine if an object is an instance of a generic type?

public  test(Object obj) {
    if (obj instanceof T) {
        ...
    }
         


        
6条回答
  •  自闭症患者
    2020-12-04 21:19

    It would make more sense to put the restriction on where the type T is used to parametrise the Class type. When you pass the type in, instead of using something like Class, you should use Class.

提交回复
热议问题