Lambda Lambda

Richard Bair richard.bair at oracle.com
Thu Mar 20 20:00:58 UTC 2014


InvalidationListener has one param, ChangeListener has 3. So the arity of the lambda tells the compiler which kind to produce. If there was ambiguity, the compiler would complain.

Richard

On Mar 20, 2014, at 12:54 PM, Scott Palmer <swpalmer at gmail.com> wrote:

> So I'm looking at Java 8 stuff now and I see that addListener has
> methods.  One takes a ChangeListener, the other an
> InvalidationListener.
> 
> So what does this do:
> 
> Node n = getSomeNode();
> n.managedProperty().addListener(x -> test(x));
> 
> Well it seems it adds an InvalidationListener.
> 
> So I tried this:
> 
> n.managedProperty().<ChangeListener>addListener(x -> test(x));
> 
> which seems to be accepted syntax, but it still adds an InvalidationListener !!!
> 
> Help Please.
> 
> Why didn't JavaFX 8 add two new methods:
> addChangeListener
> addInvalidationListener
> 
> ?
> 
> Scott



More information about the openjfx-dev mailing list