Java: Assign a Value if it is Not Null

This is just a simple one-liner. There are other solutions, but they (IMHO) miss clarity and readability.

obj = Optional.ofNullable(getNullable()).orElse(alternativeGet());

Leave a Comment

comments powered by Disqus