问题描述
我们将Java版本从8升级到了11,但是在使用Lombok的Getter和Setter注释实现POJO类时,我遇到了getter/setter方法的编译错误.
We upgraded the Java version from 8 to 11 but I got compile errors of getter/setter methods where I implemented the POJO classes with Lombok's Getter and Setter Annotations.
是否有一种方法可以使用Lombok的@Data
批注提供getter和setter而不在Java 11中实现它们?
Is there a way to use Lombok's @Data
annotation which provides getter and setter without implementing them at Java 11?
当前,我遇到了错误:
其中storeName
在类中声明为全局变量,并在类上方带有@Data Lombok注释.
where storeName
was declared as a global variable in the class with @Data Lombok annotation above the class.
推荐答案
TL; DR
将Lombok升级为依赖性并作为IDE插件( IntelliJ , NetBeans , Eclipse )并在IDE设置中启用注释处理.
Upgrade Lombok as a dependency and as a IDE plugin (IntelliJ, NetBeans, Eclipse) and enable Annotation Processing in IDEs settings.
Lombok和/或IntelliJ插件的最新版本完全支持Java 11.
Latest version of Lombok and/or IntelliJ plugin perfectly supports Java 11.
https://projectlombok.org/changelog
- ...
- 平台:对lombok的JDK10/11支持进行了许多改进.
- ...
- ...
- PLATFORM: Many improvements for lombok's JDK10/11 support.
- ...
https://github.com/mplushnikov/lombok-intellij-plugin
最新版本(0.23)已于2018年12月17日发布
...
- 经过测试并支持IntelliJ版本:2016.2、2016.3、2017.X, 2018.X
- Tested and supports IntelliJ versions: 2016.2, 2016.3, 2017.X, 2018.X
...
龙目岛项目依赖项
确保已添加Lombok依赖项 到您的项目.该插件不会自动为您添加.
Make sure you have Lombok dependency added to your project. This plugin does not automatically add it for you.
请注意:使用最新版本的Lombok依赖项是 推荐,但不能保证引入所有功能 将可用.有关更多详细信息,请参见Lombok更新日志.
...
因此,请将您的lombok/插件版本更新为最新版本.应该像魅力一样工作.
So please update your lombok/plugin version to the latest ones. Should work like a charm.
这篇关于无法在Java 11中使用Lombok的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!