Le 26/10/2009 15:56, Paul Benedict a écrit :
Since we're talking Map, I think a more utility would be gained by
including putIfAbsent (see java.util.concurrent) because I see many
lines of code that do that idiom all the time.
This idiom is especially prevalent when the value is itself a nested collection.
Map<Object, List<Object>> map = ...
List<Object> collection = map.get(key);
if (collection == null) {
collection = new LinkedList<Object>();
map.put(key, collection);
}
collection.add(value);
Paul
Paul, you need closures for that one.
Rémi