A couple Collection
methods can be called with arguments of an incorrect type, but doing so is pointless and likely the result of
using the wrong argument. This rule will raise an issue when the type of the argument to List.contains
or List.remove
is
unrelated to the type used for the list declaration.
List<String> list = new ArrayList<String>(); Integer integer = Integer.valueOf(1); if (list.contains(integer)) { // Noncompliant. Always false. list.remove(integer); // Noncompliant. list.add(integer) doesn't compile, so this will always return false }