Why doesn't the Map interface in Java have a removeAll(Collection> c) method to remove keys, like it has map.remove(Object)?
I know I can always do map.keySet().removeAll(..) .. but is this a reason that Map doesn't have removeAll() and encourages us to go with map.keySet().removeAll(..) ?
解决方案
The philosophy behind the collections APIs is to be as small and simple as possible. The Collection views on Map allow you to perform this operation already, so there is no need for an extra method.
The keySet method returns a view of the Map. Operations on the key set are reflected on the map.
The more general question on interface design: Why doesn't interface X have convenient method Y? is addressed in more depth by Martin Fowler's discussion of MinimalInterface vs HumaneInterface.