繁体   English   中英

'instanceof'的泛型运行时检查

[英]Generics runtime check of 'instanceof'

我有一个名为Node<Value>的对象。 对象NodeInternal<Value>NodeLeaf<Value>继承自Node<Value>

我试图使用instanceof测试对象的类型,如下所示:

if (node instanceof NodeInternal) 我没有添加<Value>因为在运行时,类型被删除。 但是,如果没有NodeInternal上的<Value> ,我会收到以下警告: 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

在这种情况下我该怎么办?

使用无界通配符:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM