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;

}

114 Upvotes

136 comments sorted by

View all comments

Show parent comment

4

u/Ifeee001 Feb 18 '26

Part of what makes a language nice is not having to use a library for every little thing. Something as simply as using a default value should not have to be disconnected from the standard library. Yes, it's as easy as editing a config file or running a command, but it's still not connected to the regular user experience.

Languages evolve. The popular and default way to do somethings in 2008 SHOULD be different from how it's done in 2026 because if it's not, then that means absolutely no progress has been made throughout that time.

Saying something that makes no sense doesn't necessarily make it a hot take.

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?