具有默认值的不同构造函数Lombok

时间:2018-02-25 22:52:28

标签: java lombok

是否可以使用Lombok的注释获得相同的代码?我使用@AllArgsArgument,@ RequiredArg,@ NoArgs尝试了许多不同的配置。如果没有在construcor中提供,那么使用默认的null / 0值将它们设为final是很好的。

@Builder
@EqualsAndHashCode
@Getter
public class ProductBasicDto implements Serializable {

@Builder.Default
private Long id = null;
private String name;
private String category;
private BigDecimal price;
private int stock;
private String shortDescription;

public ProductBasicDto(){

}

public ProductBasicDto(String name) {
    this.name = name;
}

public ProductBasicDto(String name, String category) {
    this(name);
    this.category = category;
}

public ProductBasicDto(String name, String category, BigDecimal price) {
    this(name, category);
    this.price = price;
}

public ProductBasicDto(String name, String category, BigDecimal price, int stock) {
    this(name, category, price);
    this.stock = stock;
}

public ProductBasicDto(String name, String category, BigDecimal price, int stock, String shortDescription) {
    this(name, category, price, stock);
    this.shortDescription = shortDescription;

}

public ProductBasicDto(Long id, String name, String category, BigDecimal price, int stock, String shortDescription) {
    this(name, category, price, stock, shortDescription);
    this.id = id;
}

}

0 个答案:

没有答案