Serialization opt-in syntax (again)

Kevin Bourrillion kevinb at google.com
Fri Sep 28 12:34:18 PDT 2012


Well, to me the positioning of "implements Whatever" after the argument
list looks invasive and unnatural.  It makes me think "how exactly is
the *argument
list* implementing this interface?"

Even though none of the options we've found are *great*, I still think
there are some better than this.


On Fri, Sep 28, 2012 at 12:12 PM, Sam Pullara <sam at sampullara.com> wrote:

> Looks pretty good to me but I also don't use serialization.
>
> Sam
>
> On Fri, Sep 28, 2012 at 11:47 AM, Brian Goetz <brian.goetz at oracle.com>
> wrote:
> > I put all the candidate syntaxes so far in the JIRA issue for this, but a
> > new one came to light this week that we kind of like.
> >
> > The problem is: let's say you have a SAM that is not serializable, but
> you
> > want the instance to be, such as in:
> >
> >   Runnable r = () -> { };
> >
> > The problem is that we really want to specify multiple interfaces for the
> > lambda, and as long as their intersection has only one abstract method,
> that
> > should be OK.
> >
> > So, how about using the space between the closing paren and the arrow:
> >
> >   Runnable r = () implements Serializable -> { ... }
> >
> > As a bonus, if we wanted to be explicit about all the implemented
> > interfaces, this easily extends to:
> >
> >   Object p = (String s) implements Predicate<String>, Serializable -> {
> ...
> > }
> >
> >
> > This also extends nicely to inner class creation expressions.  Right now
> > there is a limit of one named supertype.  But this could be extended:
> >
> >   Predicate<String> p = new Predicate<String>() implements Serializable {
> > ... }
> >
> > In this case, there is no single-method restriction; you could implement
> > Iterator and Runnable if you wanted:
> >
> >   new Iterator<T>() implements Runnable { ... }
> >
> > Note that none of this is serialization-specific; it is simply a way of
> > being explicit about multiple supertypes in contexts there this was not
> > previously allowed.
> >
>



-- 
Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb at google.com


More information about the lambda-spec-observers mailing list