簡體   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