The add method is add (E e) , so everything is correct in this regard with the world.
remove (Object o) and contains (Object o) will act based on o.equals(e) . This allows you to do some complex things with special purpose comparison objects, which are not necessarily the type of object that is in the collection.
List<Integer> list = Arrays.asList(20, 30, 40, 50, 100); boolean moreThan60 = list.contains(new Object() { public boolean equals(Object rhs) { return ((Integer)rhs) > 60; } }); System.out.println("moreThan60 = " + moreThan60);
Not that it is always recommended, or even best practice. But this is a neat trick.
source share