我可以在instanceof
表达式中使用原始类型文字或类型变量吗?
class MyClass<T> {
{
boolean b1 = null instanceof T; // T erasure -> Object should be used
boolean b2 = 2 instanceof Integer; // Incompatible operands
}
我收到编译错误。有没有办法规避这些错误并在instanceof
表达式中使用原始类型文字/类型变量?
基本上,我想得到保证,不,我永远无法做到这一点。