I have this piece of code :
if (notificationSend.get(key) != null && notificationSend.get(key).equals(value)) {
return true;
} else {
notificationSend.put(key, value);
return false;
}
and I want to know if it is possible to refactor it using Jav8 Enhancements like compute()
, computeIfPresent()
or computeIfAbsent()
Assuming value
is non-null, you don't need to use a conditional, or any of those compute*
methods.
ValueType oldValue = map.put(key, value);
return value.equals(oldValue);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With