简体   繁体   中英

IntelliJ IDEA not supporting Lambda?

I'm working with this tutorial which uses lambda expressions.

Spring Boot - Bookmarks

But IntelliJ says always: cannot resolve method(<lambda expression>) .

What do I have to check?

this.accountRepository.findByUsername(userId).orElseThrow(() -> new UserNotFoundException(userId));

You need to change the "Project language level" to "8 - Lambdas, type annotations etc.". You can find this option in "Project Settings" -> "Project"

It looks like your IntelliJ or your project is not setup to use Java 8.

  1. Open Project Structure
  2. Look into Project Settings | Project , the value of Project SDK should be 1.8
  3. Look into Platform Settings | SDK , there should be 1.8 listed

It should look something like this:

在此处输入图片说明

In addition to the answers above look into you pom.xml file. Source and target should be 1.8 or higher. eg

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM