英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论