323 }
324 break;
325 case COMMA: // (2)
326 result.remove(lastIndex);327 break;
328 default:
329 break;
136 available.add(getLexer());
137 }
138 var instance = available.iterator().next();
139 available.remove(instance);140 inUse.add(instance);
141 return instance;
142 }
Arguments to collection remove*
methods must be of the same type as the collection itself.
Though Collection
is parameterised on the type of the contained values, Collection.remove()
is not; it accepts a parameter of type Object
instead. This means any value can be passed to a collection's remove()
method, regardless of whether the value's type matches the collection's type.
This is also exacerbated for lists that store integers; List
has both an Object
and an int
overload for remove()
that are easy to confuse.
List<Integer> ints = Arrays.asList(3);
ints.remove("3"); // this will fail silently!
Ensure that the type of the value passed to remove()
is the same as the collection's type.
ints.remove((Object)3);
java.util.Collection