Updated State of the Lambda

Alessio Stalla alessiostalla at gmail.com
Wed Oct 20 02:32:12 PDT 2010


On Wed, Oct 20, 2010 at 10:04 AM, Howard Lovatt <howard.lovatt at gmail.com> wrote:
> Hi Brian,
>
> Taking each of your points in turn:
>
> 1. Yes an IDE can help with the refactoring of inner classes to
> lambdas and the changing of this, however not everyone uses an IDE (I
> personally do but know many people who use a text editor or if they do
> use an IDE they use it like a text editor).

You could ease the transition by adding a compiler flag to warn about
the use of this inside lambdas.

> 2. I agree that abstract classes as SAM types are desirable, but the construct:
>
>   AbstractClass ac = #{ ac.sam() };
>
> will be confusing because people are used to qualifying with a class
> name, not an field/variable name. Also rather defeats the point of an
> inline definition since it must be on a separate line.

Lambdas are a new concept, people will have to adapt (or not use
them). I appreciate the distinction between lambdas and inner classes,
as the former are not merely syntax sugar for the latter. This leaves
the door open for future extensions. So, I favor a certain decoupling
between the lambda and the target SAM, and the proposed treatment of
this imho goes into the right direction in that regard.

> 3. Not defining what instanceof, getClass, etc. do is undesirable, consider:
>
>  Runnable r = #{ ... };
>  List<Runnable> l = new ArrayList<>();
>  List<Runnable> cl = Collections.checkedList( l, Runnable.class );
>  cl.add( r ); // Oops - fails because r isn't a Runnable (its only
> treated as one by the type system - not by the JVM)

No, it *is* a Runnable, that's the whole point of SAM conversion. It
can be freely passed around and invoked by code that knows nothing
about lambdas.

> You get similar issues to the checkedList issue above with
> Serializable/Cloneable; you need, at times, to be able to check if an
> object is Serializable/Cloneable.

You can check it, the problem is how it will behave at runtime when
you attempt to serialize/clone it. But AFAIK you have the same problem
with proxies.

Alessio


More information about the lambda-dev mailing list