The analyzer has detected a potential error that has to do with calling a collection method on an object whose type is different from that of the collection. This warning is triggered by such functions as remove, contains, removeAll, containsAll, retainAll, etc.
Consider the following example of incorrect use of the 'remove' method:
List<String> list = ...;
Integer index = ...;
...
list.remove(index);
The programmer intended to remove an object from the list by index, but they did not take into account that the index is an object of type 'Integer' rather than a primitive integer type. What will be called is an overloaded 'remove' method expecting an object, not an 'int'. Objects of types 'Integer' and 'String' are incompatible, so using the method as shown above will cause an error.
If the type of the "index" variable cannot be changed for some reason, the code can be fixed as follows:
List<String> list = ...;
Integer index = ...;
...
list.remove(index.intValue());
This diagnostic is classified as:
|
You can look at examples of errors detected by the V6066 diagnostic. |