I've just moved from Java 7 to 8 and my code is littered with snippets like
if (myObj != null) {
myObj.doSomething();
myObj.doOtherThing();
}
I've noticed that null-checks are sometimes considered an anti-pattern and Java 8 promotes the use of Optional. Is there any benefit to having my code look like
Optional.ofNullable(myObj).ifPresent(obj -> {
myObj.doSomething();
myObj.doOtherThing();
});
Arguably, it makes the code harder to read.