gpt4 book ai didi

java - 'instanceof' 的泛型运行时检查

转载 作者:搜寻专家 更新时间:2023-11-01 03:43:53 28 4
gpt4 key购买 nike

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

我正在尝试使用 instanceof 测试对象的类型如下:

if (node instanceof NodeInternal) .我没有添加 <Value>因为在运行时,类型被丢弃。没有 <Value>NodeInternal但是,我收到以下警告:NodeInternal is a raw type. References to generic type NodeInternal<Value> should be parameterized .

遇到这种情况怎么办?

最佳答案

使用无限通配符:

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

关于java - 'instanceof' 的泛型运行时检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7622802/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com