简体   繁体   English

Lombok 的 @SuperBuilder - 错误 java:找不到符号

[英]Lombok's @SuperBuilder - Error java: cannot find symbol

I've been using Lombok with IntelliJ for a while now.我已经将 Lombok 与 IntelliJ 一起使用了一段时间。 I have installed newest (v. 0.28) Lombok plugin, enabled annotation processing and added a Lombok dependency (v. 1.18.10) in pom.xml.我已经安装了最新的 (v. 0.28) Lombok 插件,启用了注释处理并在 pom.xml 中添加了 Lombok 依赖项 (v. 1.18.10)。 It all worked well until today, when I wanted to implement the experimental @SuperBuilder .直到今天,当我想实现实验性的@SuperBuilder时,一切都运行良好。

I have a simple hierarchy:我有一个简单的层次结构:

@SuperBuilder
public class User {
   private String a;
}

@SuperBuilder
public class Employee extends User {
   private int b;
}

@SuperBuilder
public class Employer extends User {
   private double c;
}

I wanted to set the fields from parent's class in child's builder, eg:我想在孩子的构建器中设置来自父类的字段,例如:

Employee.builder().a("Positive").b(1).build();

Employer.builder().a("Negative").c(-2.1).build();

At the first glance it all seems to work - there are no errors displayed when the file is open and the builder is fine.乍一看,这一切似乎都有效 - 当文件打开并且构建器正常时没有显示错误。 However after mvn clean compile I get the following result on every @SuperBuilder line (ie in each of those 3 classes): Error:(20) java: cannot find symbol但是在mvn clean compile 之后,我在每个 @SuperBuilder 行(即在这 3 个类中的每一个中)得到以下结果: Error:(20) java: cannot find symbol

What am I missing here?我在这里缺少什么? I tried updating Lombok plugin version and reinstalling it, but without any success.我尝试更新 Lombok 插件版本并重新安装它,但没有任何成功。

I've faced same issue and adding @SuperBuilder to the all "base" classes solved the issue.我遇到了同样的问题,@SuperBuilder添加到所有“基”类解决了这个问题。

Before:前:

abstract class Parent {
   ...
}

@SuperBuilder
class Child extends Parent {
   ...
}

After:后:

@SuperBuilder              // <- addded
abstract class Parent {
   ...
}

@SuperBuilder
class Child extends Parent {
   ...
}

Ok, I found it.好的,我找到了。 I missed that the User class was extending a basic class every entity in our application extends.我错过了 User 类正在扩展我们应用程序中每个实体都扩展的基本类。 It seemed so obvious and yet I didn't notice...看起来很明显,但我没有注意到......

Anyway, I found out only by running the mvn clean install in terminal - the output was much more verbose that the one in IntelliJ and it pointed out this class.无论如何,我只是通过在终端中运行mvn clean install才发现的 - 输出比 IntelliJ 中的输出要详细得多,并且它指出了这个类。 After adding @SuperBuilder annotation on top of it compilation was successful.在其上添加@SuperBuilder注释后,编译成功。

But @SuperBuilder(toBuilder=true) is the right way of using it.但是@SuperBuilder(toBuilder=true)是正确的使用方式。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM