I hate having to add an if-case to my mental model when it's not necessary. This is not an if situation here. It's a simple "either this or that" situation. Objects.requireNonNullElse() is a single statement that I can parse in one mental "cycle". Optional.ofNullable().orElse() requires one or two. The traditional way requires at least four, and you still have to check for side-effects.
It's not that relevant in this specific situation. But even when there's two or three additional lines in/before the if body, it unnecessarily increases the size of the mental model.
View all comments
Show parent comment
3
u/Jaded-Asparagus-2260 Feb 18 '26
I hate having to add an if-case to my mental model when it's not necessary. This is not an
ifsituation here. It's a simple "either this or that" situation.Objects.requireNonNullElse()is a single statement that I can parse in one mental "cycle".Optional.ofNullable().orElse()requires one or two. The traditional way requires at least four, and you still have to check for side-effects.It's not that relevant in this specific situation. But even when there's two or three additional lines in/before the
ifbody, it unnecessarily increases the size of the mental model.