3 ms·
Java doesn't have return type function dispatch. If you had something like: var x = map.get(k); The type of `x` could not be inferred. The best they cou
by cogman10 2y ago
Java doesn't have return type function dispatch.
If you had something like:
var x = map.get(k);
The type of `x` could not be inferred.
The best they could hope for is a signature like `Optional<V> getOpt(K);`. Which wouldn't be terribly bad as Java currently has an annoying get definition in the `Map` interface because it predates generics (The current signature is `V get(Object)`).
Regardless, if they do want to change the interface, it'd probably be best if they waited for Valhalla to land. One of the problems with `Optional` as it stands is it creates a load of GC pressure. If `Optional` is converted into a value class then there will be effectively no overhead to returning it everywhere.