本文介绍了Lombok Builder批注引发UnsupportedOperationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为项目使用Lombok.我的模型如下:
I am using Lombok for my project.My model looks like:
@Builder
@Data @AllArgsConstructor
public class ScreenDefinitionDTO {
@Singular
private List<ScreenDeclaration> screens;
}
我要执行下一个操作:
String screenName = ctx.screenName().getText();
ScreenDeclaration declaration = ParsingUtils
.buildScreenDeclaration(StringUtils.trim(screenName));
创建实例的地方:
public static ScreenDefinitionDTO buildEmptyScreenDTO() {
return ScreenDefinitionDTO.builder()
.screens(new ArrayList<>())
.build();
}
最后,我得到了:
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.add(AbstractList.java:148)
at java.util.AbstractList.add(AbstractList.java:108)
当我更改不使用Lombok构建器模式创建实例时,一切都很好:
When I changed creating the instance without Lombok builder pattern everything is fine:
public static ScreenDefinitionDTO buildEmptyScreenDTO() {
return new ScreenDefinitionDTO(new ArrayList<>());
}
我不明白Lombok的构建器模式出了什么问题?
I couldn't understand what is wrong with Lombok's builder pattern?
推荐答案
由于 GitHub问题
这就是为什么您拥有UnsupportedOperationException
为了更加确定,请在有异常的情况下重现完整的代码模式.
For greater certainty reproduce full code pattern where you have exception please.
这篇关于Lombok Builder批注引发UnsupportedOperationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!