Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Val in Lombok produces "incompatible types" error in IntelliJ but still compiles fine

I found this piece of code:

Class<? extends Enum> enumClass = Class.forName(Charsets.class.getName())
                                       .asSubclass(Enum.class);

and I wanted to refactor it using Lombok, but something unexpected happened. When I changed it to:

val enumClass = Class.forName(Charsets.class.getName())
                     .asSubclass(Enum.class);

I got this error:

enter image description here

What's suprising is that the code compiles fine, and test that uses it passes.

I am unsure whether it is a bug in the Lombok Plugin, IDE or if I am doing something wrong. Shouldn't Lombok be able to easily infer the correct type of the variable?

My question is: can I use that code safely or should I revert to the original?

I am using the most recent (at this time) InteliiJ:

IntelliJ IDEA 2016.3

Build #IU-163.7743.44, built on November 17, 2016

JRE: 1.8.0_112-release-408-b2 amd64

JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

and Lombok Plugin:

Lombok Plugin

Version: 0.13.16

like image 390
Jezor Avatar asked Dec 10 '16 11:12

Jezor


2 Answers

Preferences > Plugins > install the latest version of Lombok plugin for IntelliJ

like image 112
mim Avatar answered Nov 04 '22 14:11

mim


Confirmed to work with IntelliJ IDEA 2018.1.1 and Lombok Plugin 0.17-2018.1

like image 25
Michael Piefel Avatar answered Nov 04 '22 13:11

Michael Piefel