2

Tested on Oracle JDK 11 and latest (as of now) available version of IntelliJ IDEa (IntelliJ IDEA 2018.2.4). Project language level is Java 11.

Code

public static void main(String[] args) {
    System.out.println(List.of("AAA", "BBB", "CCC")
            .stream()
            .map((@NonNull var s) -> s.toLowerCase())
            .collect(Collectors.toList()));
}

Output

[aaa, bbb, ccc]

Everything compiles and runs fine, but editor shows compile-time error:

enter image description here

Is JEP-323 (Local-Variable Syntax for Lambda Parameters) not yet supported or it's a bug?

Mikhail Kholodkov
  • 23,642
  • 17
  • 61
  • 78
  • Not really an answer but why would you need the `var` anyway? `s -> s.toLowerCase()` should work as well. Or even a method reference. – M. Deinum Sep 27 '18 at 13:54
  • @M.Deinum `String::toLowerCase` is better, but this issue is going to become popular as people start switching to Java 11 – Andrew Tobilko Sep 27 '18 at 13:55
  • 3
    If you read the JEP, you'll see that the only real reason for adding `var` for lambda parameters is so that you may annotate it without explicitly declaring the type. Given you don't use any annotations, what use is `var` adding? – Michael Sep 27 '18 at 13:56
  • @AndrewTobilko Well if it was a case in which you needed the `var` here, here it isn't really necessary. – M. Deinum Sep 27 '18 at 13:58
  • The point is that it's a legal Java 11 structure whereas IntelliJ (Lombok plugin to be precise) thinks it's not. I will add annotation so the code will make more sense. – Mikhail Kholodkov Sep 27 '18 at 14:00

2 Answers2

2

If you have this error, you most likely have the Lombok plugin installed. It is a Lombok plugin inspection bug.

Disabling the following inspection will fix the problem:

File | Settings | Editor | Probable bugs | Lombok annotations inspection

Also inspection can be implicitly suppressed. enter image description here


The issue in Lombok-intellij-plugin project has been created:

https://github.com/mplushnikov/lombok-intellij-plugin/issues/531

Mikhail Kholodkov
  • 23,642
  • 17
  • 61
  • 78
2

You should turn off the Lombok annotations inspection until they fix the issue.

enter image description here enter image description here

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142