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;
}
113
Upvotes
View all comments
Show parent comment
1
u/Sacaldur Feb 18 '26
I said "family" for a reason. There are also HQ9++ which extends the language with object oriented concepts, and HQ9+- which adds exceptions. Very fascinating languages!
While I have your attention, did you ever come across the programming language Whitespace?