Lombok的@Builder和Javadoc创建

huangapple go评论73阅读模式
英文:

Lombok's @Builder and Javadoc Creation

问题

在我的一个项目中,我正在处理一些可能有20多个字段的POJOs。我正在使用生成器模式来使对象创建变得不那么繁琐。Lombok的@Builder注解真的能消除很多样板代码,并加快了我的工作流程。问题是,我想在我的项目中各种生成器的“setter”-like方法上添加Javadoc。我尝试过像Lombok的推荐@Getter/@Setter那样将Javadoc放到字段上,但似乎不起作用。有没有可能实现我想要的效果?

英文:

In one of my projects, I'm handling some POJOs that may have 20+ fields. I'm using the Builder Pattern to make object creation less cumbersome. Lombok's @Builder annotation really removes a lot of boilerplate code and speeds up my process. Thing is that I want to add Javadoc to the 'setter'-like methods in the various builders of my project. I've tried to put the Javadoc to the fields just like Lombok's recommendation on @Getter/@Setter but it doesn't seem to work. Is there any possible method to achieve what I want?

答案1

得分: 1

You can also use @Accessors(chain = true) instead of @Builder.

Your Getter and Setter will return your instance and you can also use Method-Chaining like in Builder Pattern.

The syntax will be like

Model model = new Model().setId(23L).setTitle("test");

We always use this instead of @Builder.

Lombok's recommendation should work with this solution.

英文:

You can also use @Accessors(chain = true) instead of @Builder.

Your Getter and Setter will return your instance and you can also use Method-Chaining like in Builder Pattern.

The syntax will be like

Model model = new Model().setId(23L).setTitle("test");

We always use this instead of @Builder.

Lomboks recommendation should work with this solution

huangapple
  • 本文由 发表于 2020年8月11日 01:49:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/63345451.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定