[英]Lombok @Builder not working in lombok-1.16.18 java:cannot find symbol builderclass
@Builder
public class ProcessorLombokBO {
private String panel;
private String motherBoard;
private String ram;
private String hardDisk;
}
public static void main(String[] args) {
ProcessorLombokBO processorLombokBO =
new ProcessorLombokBO.ProcessorLombokBOBuilder()
.panel("Brown")
.hardDisk("SanDisk 256GB")
.ram("4GB")
.motherBoard("Intel")
.build();
System.out.println(processorLombokBO);
}
I am trying to implemenent @Builder
in a POJO, but it gives the below error when I execute the main
method.我正在尝试在 POJO 中实现
@Builder
,但是当我执行main
方法时它给出了以下错误。
java: cannot find symbol symbol: class ProcessorLombokBOBuilder
java:找不到符号符号:class ProcessorLombokBOBuilder
Did I miss something?我错过了什么?
Edit: Try making your inner ProcessorLombokBO class static. 编辑:尝试使您的内部ProcessorLombokBO类静态。 You can't use Builder on an inner non-static class, as the compile error at your example suggests in my IDE (Eclipse)
您不能在内部非静态类上使用Builder,因为您的示例中的编译错误建议在我的IDE(Eclipse)中
The method builder cannot be declared static;
方法构建器不能声明为static; static methods can only be declared in a static or top level type
静态方法只能在静态或顶级类型中声明
The reason is that @Builder
generates an inner static class (the ProcessorLombokBOBuilder class) and adds a static method builder()
, which is by specification only possible if the outer class is also static, because else you need an enclosing instance to reference the Builder class, which contradicts the concept of a static type. 原因是
@Builder
生成了一个内部静态类(ProcessorLombokBOBuilder类)并添加了一个静态方法builder()
,只有在外部类也是静态的情况下才能通过规范,因为否则你需要一个封闭的实例来引用Builder class,与静态类型的概念相矛盾。
Original Post: Usually you instanciate your Builder via 原帖:通常你通过实例化你的Builder
ProcessorLombokBO.builder()
If you are using mapstruct-processor
plugin in your Maven project, it will affect the builder
method.如果您在 Maven 项目中使用
mapstruct-processor
插件,它将影响builder
方法。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.2.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
Try adding the following entry to your POM, it helped in my case:尝试将以下条目添加到您的 POM 中,这对我来说很有帮助:
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.