MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/java/comments/1r7iv5p/objectsrequirenonnullelse/o654ex6/
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
1
I wasn't doubting you, but I was curious how you determined this was equivalent in performance. (To me it does 'seem' easily-optimizable)
1 u/agentoutlier Feb 19 '26 I can’t remember if I saw it with JFR or similar profiler or with -XX:+PrintInlining 1 u/j4ckbauer Feb 19 '26 Thanks, something for me to learn more about!
I can’t remember if I saw it with JFR or similar profiler or with -XX:+PrintInlining
1 u/j4ckbauer Feb 19 '26 Thanks, something for me to learn more about!
Thanks, something for me to learn more about!
View all comments
Show parent comment
1
u/j4ckbauer Feb 18 '26
I wasn't doubting you, but I was curious how you determined this was equivalent in performance. (To me it does 'seem' easily-optimizable)