I'm learning JavaFX using Intellij IDEA. When compiling the following code:
public class Main extends Application implements EventHandler<ActionEvent>{
//More code
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World");
}
//More code
});
I get the error message "Class must either be declared abstract or implement abstract method"
. But by observation of the code, I am clearly implementing the functional interface using an anonymous inner class.
When I construct an empty handle
method inside the Main
class, the code works fine, but I don't believe I should have to. What is going on!