Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 455
Dancrumb Avatar asked Nov 20 '12 16:11

Dancrumb


People also ask

Why do we need to check for self-assignment in an assignment operator?

The general reason to check for self-assignment is because you destroy your own data before copying in the new one. This assignment operator structure is also not strongly exception safe.

Why do we overload the assignment operator?

You can overload the assignment operator (=) just as you can other operators and it can be used to create an object just like the copy constructor.

Why do we overload assignment operator in C++?

Overloading assignment operator in C++ The compiler generates the function to overload the assignment operator if the function is not written in the class. The overloading assignment operator can be used to create an object just like the copy constructor.


1 Answers

Make sure that pepperWorkflowInstance has parameter:

pepperWorkflowInstance = new PepperWorkflowInstance<SomeClass>();

See IDEA-6254.

like image 141
tcb Avatar answered Sep 22 '22 05:09

tcb