How's about Collections.getSafe(...) for Map, which wouldn't return null? (original) (raw)
assembling signals assembling.signals at yandex.ru
Sun Oct 25 19:42:30 UTC 2009
- Previous message: hg: jdk7/tl/jdk: 6894633: NetHooks should not require provider to be present (sol)
- Next message: How's about Collections.getSafe(...) for Map, which wouldn't return null?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello!
I am thinking about a new method getSafe(...) for the "Collections" utility class.
It would do get(...) on a map, but instead of returning null (when an entry is not found), it would throw NoSuchElementException.
@Nonnull public static <K,V> V getSafe(Map<K,V> map, Object key){ if(!map.containsKey(key)) { throw new NoSuchElementException(/* some message here */); }
return map.get(key); }
What do you think about it?
- Previous message: hg: jdk7/tl/jdk: 6894633: NetHooks should not require provider to be present (sol)
- Next message: How's about Collections.getSafe(...) for Map, which wouldn't return null?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]