Dancrumb
Dancrumb

Reputation: 27539

Why can assignment from one type to the same need checking?

I'm running IntelliJ's Code Analyzer (IntelliJ 11.1.4) on a class and am getting this warning:

Unchecked assignment: 'java.util.List' to 'java.util.List '

The code it complains about is:

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

For reference:

public class PepperWorkflowInstance<T extends PepperWorkflowInstanceData> implements Serializable {

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

So the types match... so why would I need to 'check' the assignment?

Upvotes: 6

Views: 176

Answers (2)

tcb
tcb

Reputation: 2814

Make sure that pepperWorkflowInstance has parameter:

pepperWorkflowInstance = new PepperWorkflowInstance<SomeClass>();

See IDEA-6254.

Upvotes: 1

Pawel Solarski
Pawel Solarski

Reputation: 1048

If the pepperWorkflowInstance is of super class where raw type is used as return type, then that may generate that message.

Example.

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                        
    }
}

Upvotes: 0

Related Questions