Java – Generic runtime check for ‘instanceof’

I have an object named node < value > The objects nodeinternal < value > and nodelef < value > inherit from node < value >

I tried to use instanceof to test the type of object, as follows:

if(node instanceof NodeInternal). I didn't add < value > because the type was deleted at run time There is no < value > but on nodeinternal, I get the following warning: nodeinternal is a primitive type References to generic type nodeinternal < value > should be parameterized

What should I do in this case?

Solution

Use unbounded wildcards:

if (node instanceof NodeInternal<?>) 
  node = ((NodeInternal<Value>) node).SE();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>