listeners and lambda method reference

Remi Forax forax at
Tue Feb 10 18:19:46 UTC 2015

Hi Sebastian, Hi Maurizio,

On 02/10/2015 06:18 PM, Maurizio Cimadamore wrote:
> Hi Sebastien,
> the identity of an instance obtained through capture is 'unreliable'. 
> In case of method references is not unthinkable considering adding an 
> equals() implementation which takes into account all the parameters to 
> the bootstrap method used to forge a new instance of the functional 
> interface, but that's not how things work now. 

changing a lambda to an equivalent method ref and vice versa should be 
possible without thinking too much,
captured values can be not accessible to the lambda proxy (if they are 
inserted into the method handle),
and debugging auto-generated equals/hashCode is not fun at all ...

> An alternative way to express the idiom now is:
> Listener l = this::propertyChanged;
> ...
> property.addListener(l);
> ...
> property.removeListener(l);
> Which will do what you expect (as there's only one capture there).


> Maurizio


More information about the lambda-dev mailing list