r/java • • 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;

}

113 Upvotes

136 comments sorted by

View all comments

Show parent comment

1

u/narrow-adventure Feb 18 '26

Interesting, we don’t disagree about languages evolving, I think well thought out features that simplify development are great. I just don’t think this is it, I think we’re adding a lot of bloat to the language. I could be wrong and the next 10-15 years will definitely prove it one way or the other.

The ‘hot take’ was a joke, but which parts of it do you find nonsensical? I was trying to make a parallel (and maybe poorly) between scala a crazy feature packed language in 2016 and it’s trajectory (downwards) and Javas future trajectory if it keeps adding things at this pace. But if you have genuine thoughts about this I’m all ears, like do you think it’s not changing too fast?