Im trying to use the IntelliJ IDE to write a JavaFX program, however when the lambda expression is used, I get an error message followed by a compile error
Overrides method in javafx.event.EventHandler
package sample;
import javafx.application.Application
import javafx.scene.control.*;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage window) throws Exception {
window.setTitle("Window Title");
Button button = new Button("Click me");
button.setOnAction(e -> System.out.println("Hello World"));
}
}
To specify, it is set up as a JavaFX program, in project structure I have the Project SDK set to 10.0.1 and I have the language level set to 8
Is there something missing that I need in order to use lambda expressions?
Why would that be a problem, though? He does not seem to use any language feature not already in 8...
@Itai compiler options are not correct when Java 10 is used with Java 8 language level. The new module system is not active and compiler reports errors. Another solution is to use JDK 8 for the project.
Ah, ok, that makes sense. I have yet to use the new module system. If that is the case, presumably language level 9 would also work?
@Itai yes, level 9 will also fix the problem.
@TylerJames it's just the icon in the gutter, it's informational only and you can disable it if you don't like how it looks. If you want this icon to appear in a different color, request is welcome at youtrack.jetbrains.com/issues/IDEA.