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?
