Error: Lambda expressions are allowed only at source level 1.8 or above

这个问题也是奇葩,前几天还好好的,突然打开 idea 运行项目就报这个错误,真是无语了,网上搜了一波,终于解决了

  • 检查 pom 文件的 targetsource

    <properties>
        <maven.compiler.source>1.8maven.compiler.source>
        <maven.compiler.target>1.8maven.compiler.target>
    properties> 

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>3.7.0version>
                <configuration>
                    <source>1.8source>
                    <target>1.8target>
                    <encoding>UTF-8encoding>
                configuration>
            plugin>
        plugins>
    build>
  • 检查项目的编译环境

    Error: Lambda expressions are allowed only at source level 1.8 or above_第1张图片

    Error: Lambda expressions are allowed only at source level 1.8 or above_第2张图片

    Error: Lambda expressions are allowed only at source level 1.8 or above_第3张图片

    Error: Lambda expressions are allowed only at source level 1.8 or above_第4张图片

    打开 idea 设置

    Error: Lambda expressions are allowed only at source level 1.8 or above_第5张图片

  • 检查项目下的 .settings/org.eclipse.jdt.core.prefs 文件

    eclipse.preferences.version=1
    org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
    org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
    org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
    org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
    org.eclipse.jdt.core.compiler.compliance=1.8
    org.eclipse.jdt.core.compiler.debug.lineNumber=generate
    org.eclipse.jdt.core.compiler.debug.localVariable=generate
    org.eclipse.jdt.core.compiler.debug.sourceFile=generate
    org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
    org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
    org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
    org.eclipse.jdt.core.compiler.source=1.8
  • clean 一下 maven 项目,重新运行,终于搞定了

    Error: Lambda expressions are allowed only at source level 1.8 or above_第6张图片

你可能感兴趣的:(Java)