问题
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