Val in Java – Lombok generates an “incompatible type” error in IntelliJ, but it still compiles well
•
Java
I found this Code:
Class<? extends Enum> enumClass = Class.forName(Charsets.class.getName()) .asSubclass(Enum.class);
I wanted to refactor it with Lombok, but something unexpected happened When I change it to:
val enumClass = Class.forName(Charsets.class.getName()) .asSubclass(Enum.class);
I received this error:
Surprisingly, the code compiled well and the tests using it passed
I'm not sure if it's a Lombok plug-in, an error in the IDE, or what I did wrong Shouldn't Longmu island be able to easily infer the correct type of variable?
My question is: can I use the code safely or should I restore the original code?
I'm using the latest (at this time) inteliij:
Solution
Confirm to use IntelliJ idea 2018.1 1 and Lombok plug-in 0.17-2018.1
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码