java - How to write lambda expression with EventHandler javafx -


i'm trying rewrite code

new eventhandler<mouseevent>() {      @override     public void handle(mouseevent event) {         system.out.println(e.hashcode());     } }; 

as

new eventhandler<mouseevent>(e -> system.out.println(e.hashcode())); 

and errors. mistake here?

all code write @ beginning becomes : event -> {system.out.println(event.hashcode());

so in use (example) :

somenode.addeventhandler(mouseevent.mouse_clicked,                              new eventhandler<mouseevent>() {                                @override                                public void handle(mouseevent event) {                                   // todo auto-generated method stub                                   system.out.println(event.hashcode());                                }                             }); 

can :

 somenode.addeventhandler(mouseevent.mouse_clicked,                               event -> { system.out.println(event.hashcode()); }                          ); 

because proposition try instantiate eventhandler interface cannot, can make anonymous implementation (1st way handle()) or avoid , use lambda-exp


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -