Optional.isEmpty()
Jonathan Bluett-Duncan
jbluettduncan at gmail.com
Sat Apr 22 13:31:43 UTC 2017
Hi Peter,
Your reasoning has personally convinced me that a method like `isEmpty()`
would pull its weight. However, at the risk of bikeshedding, I think it
should be named differently, as `isEmpty()` immediately makes me think that
`findModule()` returns a List, which I'd easily find confusing.
How about `isNotPresent()` instead?
Best regards,
Jonathan
On 22 April 2017 at 10:40, Peter Levart <peter.levart at gmail.com> wrote:
> 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
>
>
More information about the core-libs-dev
mailing list