Javadoc WIN – Map.keySet()
This week, I was writing a class that implements the Set interface but uses a Map internally to track usage information about the contents of the Set. I was implementing the removeAll() method, and wanted to use an Iterator over the Set returned by Map.keySet() in my method.
My question was, will the remove() method from an Iterator over a Set returned by Map.keySet() un-map the item from the underlying Map?
The answer is yes!
The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It does not support the add or addAll operations.
That is some fine documentation, folks! As developers on our own systems, we know that our peers can always look at the code and try to figure out what is going on. But, having documentation that allows the clients of your class to easily answer questions is vastly superior to people regularly resorting to looking at your code.

Shad finds high-value intersections between business strategy and information technology. He currently resides in the Madison, WI area.
Leave a Reply