r/java • u/edurbs • Feb 17 '26
Objects.requireNonNullElse
I must have been living in a cave. I just discovered that this exists.
I can code
City city = Objects.requireNonNullElse(form.getCity(), defaultCity);
... instead of:
City city = form.getCity();
if(city == null){
city = defaultCity;
}
111
Upvotes
View all comments
Show parent comment
2
u/narrow-adventure Feb 17 '26
Cool, I’m glad they worked out for you. I don’t doubt that you’re a smart guy, maybe a bit arrogant for my taste but weren’t we all when we were young?
I’ll share with you my experience of growing a product and overseeing teams of REALLY good devs: 99% of them wouldn’t be able to understand what you’re saying. It is my belief based on my experience, that might be completely wrong, that when devs see complex concepts they don’t understand fully they end up using them incorrectly or even worse misunderstanding the existing code leading to runtime bugs.
I have not had issues with binding, thorough exhaustiveness etc, but I have had to deal with a lot of bugs caused by devs not being able to understand the code, and it’s my personal belief that these will not help at all (they will make it worse).