MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/java/comments/1r7iv5p/objectsrequirenonnullelse/o5zxe0r/?context=3
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
I think the point is … less code. Less dose the better
0 u/White_C4 Feb 18 '26 Less code? You mean more abstraction which was my original point. More abstraction isn't necessarily a good thing.
0
Less code? You mean more abstraction which was my original point. More abstraction isn't necessarily a good thing.
View all comments
Show parent comment
4
u/christoforosl08 Feb 18 '26
I think the point is … less code. Less dose the better