How to generate the Builder java class for your POJO

一曲冷凌霜 提交于 2019-12-23 19:43:51

问题


I have this pojo file that consists over 50 attributes. Creating a manual builder class can be error prone activity.

Is there a easy way to generate the builder class? for e.g. If you required to generate getter setters you would normally use eclipse Source > Generate Getters and Setters Is there a painless procedure to perform this?

Really appreciate any help..


回答1:


Use Lombok.

You can annotate your class, for example:

@Data //generate getters and setters
@EqualsAndHashCode(callSuper=true) //self descriptive
@NoArgsConstructor //self descriptive
@AllArgsConstructor //self descriptive

Remark: it works only with Eclipse for now.




回答2:


I have just used Practical macros, within a few minutes of install from the market place, I could generate *constructors*, getters / setters, toString, hashcode and equals (basically chaining the standard eclipse commands) in a single command. Just what I was looking for and saved me loads of time. I can also see a lot more uses for it, well done to Earnst (the creator).



来源:https://stackoverflow.com/questions/17317010/how-to-generate-the-builder-java-class-for-your-pojo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!