I have mixed feelings about these, because there are different concepts, such as presence (#containsKey check) and nullity wrapped into a single orDefault suffix.
Basically double the amount of methods in the class with potential misinterpretation risks. Arguably the methods only hide the real conditions and are even more messy due to increased argument count.
There could be a huge difference between key: null and no key at all. One may be used for disabling some function, and the other for the actual default value. Due to that, I feel there is no other option than leaving the final choice of the condition to the developers.
Use ternary condition with #containsKey when you want to check for the presence.
Use Optional.ofNullable(data.get ...).orElse(...) when you want to check for presence + nullity.
I have mixed feelings about these, because there are different concepts, such as presence (
#containsKey
check) and nullity wrapped into a singleorDefault
suffix.Basically double the amount of methods in the class with potential misinterpretation risks. Arguably the methods only hide the real conditions and are even more messy due to increased argument count.
There could be a huge difference between
key: null
and no key at all. One may be used for disabling some function, and the other for the actual default value. Due to that, I feel there is no other option than leaving the final choice of the condition to the developers.#containsKey
when you want to check for the presence.Optional.ofNullable(data.get ...).orElse(...)
when you want to check for presence + nullity.