Migrating methods in Collections
Brian Goetz
brian.goetz at oracle.com
Thu Dec 24 19:39:40 UTC 2015
> interface AnyMap<K,V> { // ...
> Optional<V> at(K key);
> V at(K key, V defaultValue);
> }
An alternative to at(key, defaultValue) is tryAt(K, Consumer<V>) --
though the name tryAt is awful. (I was considering map() and tryMap()
as the new names for get().)
Just to put it on the record, Optional-bearing at() has a problem when
the map can have null values -- but given that there are alternatives
(default version, consumer version, legacy get()) in the cases where
this might happen, I don't see this as a showstopper.
> For Queue, there's no good reason for having an Optional-returning
> method in addition to added default-returning version, so:
Why not? Optional offers a lot of flexibility, since you have many
options for what to do with the possibly-nonexistent value (orElse,
orElseThrow, map, flatMap, ifPresent.) Seems a natural building block,
and a sharper tool than poll(defaultValue).
More information about the valhalla-spec-experts
mailing list