Description
Some Collection methods like List#remove or Map#get have type Object as arguments. Calling these methods with types unrelated to the type T of e.g. List< T > or Map< T , ? > is most likely unintended and a bug. This is very similar to “Silly equality checks should not be made” (squid:S2159).
Type
Bug
Snippet
public class UnlikelyArgumentTypeForCollectionMethodsUsingObject {
public static void main(String[] args) {
Map<Integer,Object> map = new HashMap<>();
map.remove("a string"); // Noncompliant
map.remove(8); // Compliant
}
}
Note
Also covered by Eclipse JDT.