Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Project Language level in IntelliJ IDEA?

I am using Java 7 SDK and IntelliJ IDEA IDE.

java version "1.7.0_11" Java(TM) SE Runtime Environment (build 1.7.0_11-b21) Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode) 

I am still not able to use Java 7 features. After a bit of googling I could use all the features after setting project language level to 7(Diamond, ARM, multicatch etc). What exactly is this? If this has some relationship to syntax based on JDK in use what is level 8(Lambda, annotations etc)? Java 8 isn't released yet. Java 8 is expected in March 2014 according to Wiki. Someone please explain this language level concept.

like image 245
Aniket Thakur Avatar asked Jul 18 '13 04:07

Aniket Thakur


People also ask

What is project language level in IntelliJ?

As per the documentation within section Exploring the General Project Settings at the IntelliJ Wiki, the project language level impacts the intellisense provided by the IDE. It also dictates the behavior of the compiler being used by IntelliJ when it compiles your Java code as you develop.

How do I change the language level in IntelliJ?

Module language levelFrom the main menu, select File | Project Structure Ctrl+Alt+Shift+S . Under Project Settings, select Modules | Sources. From the Language level list, select the necessary option. To use the project language level, select Project default.

What is project language?

User interface / operation. The language used in the project. The project language can be one of the dictionary languages, but it can also be a language which is not included in the dictionary. Example: You translate a project into Spanish and send it to a customer.


2 Answers

The Language level setting sets which features the code assistance in the editor should support. For example, if you're using JDK 1.7 but want your code to be compatible with JDK 1.6, you can set the language level lower than your actual JDK supports (6.0 in the case of JDK 1.6) and only get refactorings/syntax suggested that are supported on 1.6 and lower. Depending on your compiler, it may also give the compiler options to remove support for newer syntax elements.

The 8.0 (which, as you're guessing corresponds to Java 8) is available for people that want to experiment with one of the Java 8 snapshots that are available. Since Java 8 isn't released, language level 8.0 may very well change before release.

like image 172
Joachim Isaksson Avatar answered Oct 08 '22 16:10

Joachim Isaksson


If you look at the options for the javac Java compiler command, you'll see that the -source and -target options allow you to compile against alternate versions of Java. I'm not sure to which option IntelliJ's language level setting corresponds (it is likely -source), but it essentially tells IntelliJ to use the provided Java SDK (in the Project SDK field) in the specified Java language version instead of the latest provided by said SDK.

So while you have Java 7 installed, you could set the language level to 6.0, and IntelliJ will compile your code against the Java 6 specification instead of the Java 7 spec. This includes all of the real-time suggestions and code checking done as you type.

The Java 8 option is there likely due to the fact that beta builds of Java 8 are available for testing.

I've never experimented with what would happen if you set a language level to something higher than the JDK version.

like image 29
ajp15243 Avatar answered Oct 08 '22 14:10

ajp15243