6

我在一个类上运行 IntelliJ 的代码分析器 (IntelliJ 11.1.4) 并收到以下警告:

未经检查的分配:“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

2 回答 2

1

确保pepperWorkflowInstance有参数:

pepperWorkflowInstance = new PepperWorkflowInstance<SomeClass>();

请参阅IDEA-6254

于 2012-12-28T18:15:25.330 回答
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                        
    }
}
于 2012-11-20T16:39:57.620 回答