New methods in java.util.Map
Alberto Otero Rodríguez
alber84ou at gmail.com
Thu Oct 16 18:15:34 UTC 2025
Hi, I have a suggestion for new methods in java.util.Map.
As of Java 25, we have the method:
default V getOrDefault(Object key, V defaultValue)
However, I think it could be interesting a method where the defaultValue is
passed as a lambda function like this one:
default V getOrDefault(Object key, Function<? super K, ? extends V>
defaultValueFunction)
Also, other two new methods might be interesting if you want to get a value
from a map, but if the key doesn't exist you want to insert that value in
the map and return it:
default V getOrPut(Object key, V defaultValue)
default V getOrPut(Object key, Function<? super K, ? extends V>
defaultValueFunction)
What do you think?
Regards,
Alberto.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20251016/e321c070/attachment.htm>
More information about the amber-dev
mailing list