Optional class is just a Value

Vitaly Davidovich vitalyd at gmail.com
Wed Sep 19 11:45:26 PDT 2012


@Nullable is really for static analysis tools, whereas Optional is a
runtime convenience class that allows for arguably better looking code -
look at guava's Optional with its various or() overloads.  It also makes
for a clearer API as caller knows that actual return value might be
missing; having to view the set of annotations on the return type to see if
@Nullable is present seems less friendly (without some IDE support, at
least).

Sent from my phone
On Sep 19, 2012 2:38 PM, "Ben Evans" <benjamin.john.evans at gmail.com> wrote:

> At the risk of asking a possibly-stupid question, how does this
> interact with JSR 308?
>
> Surely a value which is missing is represented by a null, so wouldn't
> an alternative to Optional be a @Nullable 308 annotation?
>
> Thanks,
>
> Ben
>
> On Wed, Sep 19, 2012 at 10:55 AM, Vitaly Davidovich <vitalyd at gmail.com>
> wrote:
> > Agree, I like Optional as well.  Also, the name implies that there's
> > something special about it; Value is too generic and doesn't have the
> same
> > effect.
> >
> > Sent from my phone
> > On Sep 19, 2012 1:47 PM, "Kevin Bourrillion" <kevinb at google.com> wrote:
> >
> >> For what it's worth, the Guava team still feels very happy with our
> choice
> >> of the name Optional for this construct.  An Optional<String> *is* an
> >> optional string.  It is not an "option string".  And it rolls of the
> tongue
> >> a lot better than a "maybe string". It's certainly not well described
> as a
> >> "value string".
> >>
> >>
> >> On Wed, Sep 19, 2012 at 10:33 AM, Julian Hyde <julianhyde at gmail.com>
> >> wrote:
> >>
> >> > On Sep 19, 2012, at 8:47 AM, Paul Benedict <pbenedict at apache.org>
> wrote:
> >> >
> >> > > I think the Optional class could be better named. I consider it a
> >> > negative
> >> > > noun -- focusing on its ability to not contain a value.
> >> >
> >> > The name made sense to me... but then I was familiar with the similar
> >> > concept in Scala.
> >> >
> >> > http://www.scala-lang.org/api/current/scala/Option.html
> >> >
> >> > On reflection, the Scala name makes more sense. "Optional" (adjective)
> >> > implies behavioral (hence usually applies to an interface) whereas
> >> "Option"
> >> > (noun) implies structural.
> >> >
> >> > Julian
> >> >
> >> >
> >>
> >>
> >> --
> >> Kevin Bourrillion | Java Librarian | kevinb at google.com | 650-450-7126
> >>
> >>
> >
>


More information about the lambda-dev mailing list