Final defenders

Rémi Forax forax at
Tue Aug 7 14:39:05 PDT 2012

On 08/07/2012 08:16 PM, Aleksey Shipilev wrote:
> On 08/07/2012 09:55 PM, "Zdeněk Troníček" wrote:
>> StatefulOp should be declared as abstract class, not interface.
>> Concerning the final methods in interfaces, I view default methods as a
>> means for API evolution and from this point of view, they do not seem
>> particularly useful.
> Yes, in the Java 5-7 they indeed should be abstract base classes. But in
> this case, lambdas requiring functional interfaces. Making StatefulOp an
> abstract class will prohibit making a StatefulOp-typed lambda.
> Maybe the answer lies in allowing lambdas implement abstract classes,
> but that would be MUCH more mess than allowing final defenders.

Hi Aleksey,
a lambda can not be created from an abstract class without loosing a lot.
First, because you have to call a constructor or initalizing fields if 
it's an abstract class, it means that the VM can't delay the creation of 
the lambda or cache the resulting instance because the creation of an 
instance is observable.
Moreover, because you have to inherits from the abstract class this also 
mean that the VM can not create a fake class with a special shape that 
by example store a direct pointer to the lambda body in the instance 
instead of storing it in the itable leading to fewer indirections when 
invoking a lambda.

Lambda are better inner classes not just a syntax sugar.

> -Aleksey.


More information about the lambda-dev mailing list