Make Intellij IDEA allow lambda in java 5 6 7 lang

2019-04-08 08:53发布

问题:

Because of retrolambda, we can use java 8 lambda feature in java 5 6 7. so, How to make Intellij Idea allow lambda in java 5 6 7 language level, also with ide features for lambda ?

回答1:

In IntelliJ IDEA you will need to set the language level for the module to be Java 8, or else IDEA will give red squiggly lines about lambda expressions.

In Settings | Inspections | Java language level migration aids | Usages of API documented as @since 1.5 (1.6|1.7) you can choose it to warn about usages of API that is documented as @since 1.8.

Additionally you should run all the tests for your project using the Java 7 runtime, or whatever is your target. For Maven this can be configured using Surefire's jvm property. During development, inside IDEA, it's more practical to run the tests just with Java 8.