Hi,

Seeing the following line in some JDK test that was up for review:

    return cf.findModule(target).orElse(null) == null;

I immediately jumped to suggest it would look better if written as:

    return !cf.findModule(target).isPresent();


But then I leaned back and asked myself: "Would it really?"

The boolean negation in front of a chain of method calls tends to visually disappear from the view when we finally reach the offending method and might get missed when quickly browsing the code. In this respect, ".orElse(null) == null" is actually better. But the best would of course be something like that:

    return cf.findModule(target).isEmpty();

What do you think? Would this pull its weight?

Regards, Peter

Reply via email to