MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/java/comments/1r7iv5p/objectsrequirenonnullelse/o5y0x4f/
r/java • u/edurbs • Feb 17 '26
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;
}
136 comments sorted by
View all comments
Show parent comment
4
Old man shouts at clouds...this api has been available since 2017. Almost 10 years ago.
0 u/narrow-adventure Feb 17 '26 Gosh darn kids and their modern 10yo APIs lol
0
Gosh darn kids and their modern 10yo APIs lol
View all comments
Show parent comment
4
u/kiteboarderni Feb 17 '26
Old man shouts at clouds...this api has been available since 2017. Almost 10 years ago.