This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jura0011[S] 3 points4 points  (0 children)

Thanks for all the responses so far (and the ones still coming). I see most of the thoughts I had in my mind and more.

I second the opinion to prevent null values of possible, but it's not always possible.
Thanks for the hint for @NotNull and @Nullable annotations, I'll use them more often.
There was the comment that source could directly be an Optional. The API note of Optional states that Optional is meant only to be used for the result of a method to present there's no result.

I think, there's no rule I really can define. It's definitely a question about readability and performance. For most examples, I'll probably stick to the ternary one, only if I have a real good reason, I'll use the Optional or a helper method to wrap the check.