hg: lambda/lambda/jdk: Cleanup in Optional
Ricky Clarkson
ricky.clarkson at gmail.com
Fri Nov 23 03:20:47 PST 2012
That's a useful method but I'd suggest calling it 'option' or
'fromNullable'. You might be calling .of(T) thinking you do not have null
and you'd rather have an exception than an empty Optional as the result.
For reference, Scala calls it option, Guava calls it fromNullable,
Functional Java calls it fromNull and all 3 make that a distinct method
from the one that throws an exception if it's null (Some(t) in Scala, of in
Guava, some(t) in Functional Java).
On Fri, Nov 23, 2012 at 5:36 AM, Gernot Neppert <mcnepp02 at googlemail.com>wrote:
> Hi Brian,
>
> I do think that having factory methods 'empy()' and 'of(T)' and no public
> constructor is a good thing, I wonder whether it's necessary to make
> 'of(T)' is so restrictive: it throws NullPointerException if the supplied
> value is null.
> So why place the burdon of picking the correct factory method upon the
> user?
> Why not simply have:
>
> public static <T> Optional<T> of(T value) {
> return value == null ? empty() : new Optional<T>(value);
> }
>
>
>
>
> 2012/11/15 <brian.goetz at oracle.com>
>
> > Changeset: ab258565c0c9
> > Author: briangoetz
> > Date: 2012-11-15 17:19 -0500
> > URL: http://hg.openjdk.java.net/lambda/lambda/jdk/rev/ab258565c0c9
> >
> > Cleanup in Optional
> >
> > ! src/share/classes/java/util/Optional.java
> > ! src/share/classes/java/util/streams/ops/FindAnyOp.java
> > ! src/share/classes/java/util/streams/ops/FindFirstOp.java
> > ! src/share/classes/java/util/streams/ops/SeedlessFoldOp.java
> >
> >
> >
>
>
More information about the lambda-dev
mailing list