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

后端 未结 7 1759
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:30

    After compiling statement o instanceof T would be o instanceof Object and because all types derives from Object, it will always evaluate to true. Allowing this kind of tests would give false positive results

提交回复
热议问题