Why “t instanceof T” is not allowed where T is a type parameter and t is a variable?

后端 未结 7 1774
Happy的楠姐
Happy的楠姐 2021-01-05 11:03

Eclipse says that the instanceof operation is not allowed with Type Parameter due to generic type eraser.

I agree that at runtime, no type information stays. But con

7条回答
  •  佛祖请我去吃肉
    2021-01-05 11:37

    The generic type arguments are not known at runtime, so there is no class you can compare with. T is only known at compile time. Generics do only help the developer to write code easier. But at runtime, the arguments are just Object instances.

提交回复
热议问题