lambda expressions are not supported at this language level intellij

封巍發表於2017-01-23

環境:intellij 14.0.2, jdk 1.8

編譯錯誤:lambda expressions are not supported at this language level intellij


操作1:(如果刪除了專案檔案,如.idea .iml, 下次開啟專案需重新配置)

To compile with Java 8 (lambdas etc) in IntelliJ;

  • CTRL + ALT + SHIFT + S or File / Project Structure

  • Open Project tab

  • Set Project SDK to compatible java version (1.8)

  • Set Project language level to 8

  • Open Modules tab

  • Set Language level to 8, click OK

  • CTRL + ALT + S or File / Settings

  • Build, Execution, Deployment / Compiler / Java Compiler

  • Change Target bytecode version to 1.8, click OK

操作2: (一次配置永久生效)

add the following content to pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>


參考:

http://stackoverflow.com/questions/22703412/java-lambda-expressions-not-supported-at-this-language-level

相關文章