javaintellij-ideasdkjava-21

Can't use latest Java Version (JDK 21) in Intellij IDEA


I'm using macOS and I want to try Java 21 in Intellij IDEA. I believe I have done all the required steps to change Java version of a project / module. Nevertheless I still can't use new Java 21 Features, such as String Templates. How to be able to use Java 21 in Intellij?

enter image description here

I have changed:

  • Project SDK to 21

  • Module SDK to 21

  • OS java version to 21. Typing java -version in terminal outputs:

    java version "21" 2023-09-19 LTS

    Java(TM) SE Runtime Environment (build 21+35-LTS-2513)

    Java HotSpot(TM) 64-Bit Server VM (build 21+35-LTS-2513, mixed mode, sharing)

  • I have also updated Intellij to version 2023.2


Solution

  • I needed to update Intellij version to 2023.2.2 and change Language level (File -> Project structure -> project -> language level) to 21 (preview)

    language level 21 (preview) The new language level won't show up until Intellij is updated to the latest version.

    To update Intellij, I needed to manually check for new update

    Manually updating Intellij on Mac

    Intellij IDEA | Check for Updates

    enter image description here

    Manually updating Intellij on Windows / Linux

    File | Settings | Appearance & Behavior | System Settings | Updates

    enter image description here