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 consider the following generic declaration of class :
class SomeClass<T>{
T t;
SomeClass(Object o){
System.out.println(o instanceof T); // Illegal
}
}
At runtime, no T would be present! But if I instantiate this class of type Integer, then the corresponding object will have a field t of type Integer.
Then, why can't I check the type of a variable with T which can be replaced by Integer at runtime. And I would be actually doing something like "o instanceof Integer".
Under which cases, allowing instanceof with a Type Parameter can cause trouble so that it is prohibited?