Why aren't Java Collections remove methods generic?
Asked 07 September, 2021
Viewed 974 times
  • 52
Votes

Why isn't Collection.remove(Object o) generic?

Seems like Collection<E> could have boolean remove(E o);

Then, when you accidentally try to remove (for example) Set<String> instead of each individual String from a Collection<String>, it would be a compile time error instead of a debugging problem later.

10 Answer