[英]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. 我想使用龙目岛(Lombok)对其进行重构,但是发生了意外情况。 When I changed it to:
当我将其更改为:
val enumClass = Class.forName(Charsets.class.getName())
.asSubclass(Enum.class);
I got this error: 我收到此错误:
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. 我不确定这是Lombok插件,IDE中的错误还是我做错了什么。 Shouldn't Lombok be able to easily infer the correct type of the variable?
Lombok是否应该能够轻松推断出变量的正确类型?
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: 我正在使用最新的(当前)InteliiJ:
IntelliJ IDEA 2016.3
IntelliJ IDEA 2016.3
Build #IU-163.7743.44, built on November 17, 2016
Build#IU-163.7743.44,建于2016年11月17日
JRE: 1.8.0_112-release-408-b2 amd64
JRE:1.8.0_112-release-408-b2 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains sro
JVM:JetBrains sro的OpenJDK 64位服务器VM
and Lombok Plugin: 和龙目岛插件:
Lombok Plugin
龙目岛插件
Version: 0.13.16
版本:0.13.16
确认可与IntelliJ IDEA 2018.1.1和Lombok插件0.17-2018.1一起使用
Preferences > Plugins
>为IntelliJ安装最新版本的Lombok插件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.