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
Post a Comment