Generici Java - No instanceOf

Poiché il compilatore utilizza la cancellazione del tipo, il runtime non tiene traccia dei parametri del tipo, quindi in fase di runtime la differenza tra Box <Integer> e Box <String> non può essere verificata utilizzando l'operatore instanceOf.

Box<Integer> integerBox = new Box<Integer>();

//Compiler Error:
//Cannot perform instanceof check against 
//parameterized type Box<Integer>. 
//Use the form Box<?> instead since further 
//generic type information will be erased at runtime
if(integerBox instanceof Box<Integer>) { }