I've recently seen a blog post (tweeted by @java) that suggests the following code is becoming increasingly common:
Optional.ofNullable(i).ifPresent(x -> doBlah(x));
instead of:
if (i != null) {
doBlah(i);
}
The use of Optional in this case appears very awkward to me, even ignoring the naming of the variables - the latter is easier to read and more idiomatic for the use case (handling nulls). I believe this also captures semantics better - i is likely from code that doesn't adhere to the semantics that Optional is trying to capture (as described in the possible duplicate and in this Oracle article).
I do not see one, but is there a good semantic cause to prefer the Optional.isNullable approach (ignoring the performance impact it may have depending on how it is used)?