【发布时间】:2011-01-31 18:26:06
【问题描述】:
我可以在instanceof 表达式中使用原始类型文字或类型变量吗?
class MyClass<T> {
{
boolean b1 = null instanceof T; // T erasure -> Object should be used
boolean b2 = 2 instanceof Integer; // Incompatible operands
}
我收到编译错误。有什么办法可以规避这些错误并在 instanceof 表达式中使用原始类型文字/类型变量?
基本上,我想放心,不,我永远做不到。
【问题讨论】:
标签: java instanceof