RFR 8071670: java.util.Optional: please add a way to specify if-else behavior

Louis Wasserman lowasser at google.com
Thu Feb 12 21:16:28 UTC 2015


Sure.  The "if present":"if present else":"if absent" ratio is ~24:6:1.

On Thu Feb 12 2015 at 1:01:51 PM Paul Sandoz <paul.sandoz at oracle.com> wrote:

>
> On Feb 12, 2015, at 8:29 PM, Louis Wasserman <lowasser at google.com> wrote:
>
> > I'm not sure I can share hard numbers, but the ratio of
> >
> > if (optional.isPresent()) {
> >   // non-returning statements here
> > }
> >
> > to
> >
> > if (optional.isPresent()) { // or negated
> >   // non-returning statements here
> > } else {
> >   // non-returning statements here
> > }
> >
> > is ~5.5x in favor of the no-else case.  Both patterns have large numbers
> of hits, though, so I'm satisfied that this is not an unreasonable thing to
> do.
>
> Many thanks, that's good to know.
>
>
> >
> > I can possibly try to extract statistics on how many of these cases
> would be easily converted to method references and other things that might
> be easier to express with functional interfaces, but I'm not sure how
> necessary that actually is.
> >
>
> It might be interesting, but i would be more curious about the following
> case:
>
> if (!optional.isPresent()) {
> ...
> }
> // no else
>
> would it be possible to get some numbers on that?
>
> Thanks,
> Paul.
>



More information about the core-libs-dev mailing list