2012-11-20 41 views
6

我上的類運行的IntelliJ的代碼分析器(11.1.4的IntelliJ)和我得到這樣的警告:爲什麼從一種類型到同一種類型需要檢查?

未選中分配: 'java.util.List的' 到 'java.util.List的'

它抱怨的代碼的是:

List<String> targetDocumentIds = pepperWorkflowInstance.getTargetDocumentIds(); 

參考:

public class PepperWorkflowInstance<T extends PepperWorkflowInstanceData> implements Serializable { 

    private List<String>   targetDocumentIds = new ArrayList<String>(); 
    ... 
    public List<String> getTargetDocumentIds() { 
     return targetDocumentIds; 
    } 
    ... 
} 

因此,類型匹配...所以爲什麼我需要'檢查'作業?

+4

什麼類型是'pepperWorkflowInstance'實例中的'targetDocumentIds'? – jn1kk

+0

剛剛意識到這是一個IntelliJ警告,而不是JVM。你有什麼版本的IntelliJ? – jn1kk

+0

進行編輯以解決註釋 – Dancrumb

回答

0

如果pepperWorkflowInstance屬於超類,其中原始類型用作返回類型,那麼可能會生成該消息。

例子。

class A{ 
    public List getTargetDocumentIds(){ 
     return new ArrayList(); 
    } 
} 

class B extends A{ 
    public List<String> getTargetDocumentIds(){ 
     return new ArrayList<String>(); 
    } 
} 

public class Tester { 

    public static void main(String[] args) { 
     A a = new B(); 
     List<String> targetDocumentIds = a.getTargetDocumentIds(); 
     // above produces compiler type safety warning       
    } 
} 
+0

謝謝,但我不確定適用於我的情況......儘管如此。 – Dancrumb

1

確保pepperWorkflowInstance具有參數:

pepperWorkflowInstance = new PepperWorkflowInstance<SomeClass>(); 

IDEA-6254

相關問題