Checking generics runtime for instanceof instance

I have an object named Node<Value> . NodeInternal<Value> and NodeLeaf<Value> objects inherit from Node<Value> .

I am trying to check what type of object is used with instanceof as follows:

if (node instanceof NodeInternal) . I did not add <Value> because at runtime the type is discarded. Without <Value> on NodeInternal , however, I get the following warning: NodeInternal is a raw type. References to generic type NodeInternal<Value> should be parameterized NodeInternal is a raw type. References to generic type NodeInternal<Value> should be parameterized .

What should I do in this case?

+4
source share
2 answers

Use unlimited template:

 if (node instanceof NodeInternal<?>) node = ((NodeInternal<Value>) node).SE(); 
+1
source

All Articles