简体   繁体   English

Lombok中的Val在IntelliJ中产生“不兼容类型”错误,但仍可正常编译

[英]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.1Lombok插件0.17-2018.1一起使用

Preferences > Plugins >IntelliJ安装最新版本的Lombok插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IDE中出现“不兼容类型”错误,但代码已编译 - “Incompatible Types” error in IDE, but code compiles Lombok @SuperBuilder on abstract class with generic cause error: incompatible types - Lombok @SuperBuilder on abstract class with generic cause error: incompatible types IntelliJ 无法识别 Lombok 方法但编译成功 - IntelliJ not recognising Lombok methods but compiles successfully Lambda在Java 9中导致编译错误“不兼容的类型”,在Java 8中编译 - Lambda causes compile error “incompatible types” in Java 9, compiles in Java 8 使用 lombok.Getter(lazy = true) 和 java 10 的不兼容类型错误 - Incompatible types error using lombok.Getter(lazy = true) with java 10 Lombok 的 IntelliJ IDEA 编译错误 - IntelliJ IDEA compilation error with Lombok Intellij groovy“类型不兼容的赋值” - Intellij groovy “assignments with incompatible types” 为什么此代码片段会产生 `error: incompatible types: ArrayList<string> 不能转换为<anonymous arraylist<string> >`?</anonymous></string> - Why this code snippet produces `error: incompatible types: ArrayList<String> cannot be converted to <anonymous ArrayList<String>>`? Java 8不兼容类型错误 - Java 8 Incompatible Types Error AlertDialog不兼容的类型错误 - AlertDialog Incompatible types error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM