[英]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.