@Data @EqualsAndHashCode(callSuper = true) @SuperBuilder @AllArgsConstructor @NoArgsConstructor @ToString(callSuper = true) public class Me extends Father { private String color; } @Data @EqualsAndHashCode(callSuper = true) @SuperBuilder @AllArgsConstructor @NoArgsConstructor @ToString(callSuper = true) public class Father extends GrandFather { private int id; } @Data @SuperBuilder @AllArgsConstructor @NoArgsConstructor public class GrandFather { private int age; } // test Me me = Me.builder() .color("red") .id(555) .age(78) .build(); System.out.println(me); System.out.println(me.getColor()); System.out.println(me.getAge());
※必需使用 @SuperBuilder 註解,父子類都要,使用 1.18.16 版本測試的
沒有留言:
張貼留言