<div dir="ltr"><div>Hi, I have a suggestion for new methods in java.util.Map.</div><div><br></div><div>As of Java 25, we have the method:</div><div><br></div><div style="margin-left:40px">default V getOrDefault(Object key, V defaultValue)</div><div><br></div><div>However, I think it could be interesting a method where the defaultValue is passed as a lambda function like this one:</div><div><br></div><div style="margin-left:40px">default V getOrDefault(Object key, Function<? super K, ? extends V> defaultValueFunction)</div><div><br></div><div>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:</div><div><br></div><div><div style="margin-left:40px">default V getOrPut(Object key, V defaultValue)</div><br></div><div style="margin-left:40px">
default V getOrPut(Object key, Function<? super K, ? extends V> defaultValueFunction)</div><div><br></div><div>What do you think?</div><div><br></div><div>Regards,</div><div><br></div><div>Alberto.</div></div>