Lambdas and serialization

Nathan Bryant nathan.bryant at linkshare.com
Tue Oct 19 10:48:52 PDT 2010


It does seem like there is a more general issue: simply that they're
anonymous. How do you safely serialize something that has no
reliably-defined name, or a name that's just a byproduct of whatever the
compiler decided to call it?

For example, if you pass one over RMI, I think the peer will try to
resolve that name locally, and might resolve it the wrong way. Only if
it can't find the name will it attempt to download the bytecode from the
other end.

-----Original Message-----
From: lambda-dev-bounces at openjdk.java.net
[mailto:lambda-dev-bounces at openjdk.java.net] On Behalf Of Bob Lee
Sent: Tuesday, October 19, 2010 1:18 PM
To: Brian Goetz
Cc: lambda-dev
Subject: Re: Lambdas and serialization

FWIW, anonymous inner classes can technically be serializable (insofar
as
they can implement Serializable), but it's typically not safe to do so
because their internal state is unspecified. In other words, the
serializable form of an anonymous inner class from one compiler may not
be
compatible with another.

I've personally always wanted anonymous classes to be safely
serializable so
I could use them in HTTP sessions, RPCs, etc.

Bob



More information about the lambda-dev mailing list