Java+;龙目山+;番石榴;验证

Java+;龙目山+;番石榴;验证,java,guava,lombok,Java,Guava,Lombok,我有一个Pojo: @Getter @EqualsAndHashCode public class Order { public enum OrderType { BUY, SELL } private Id id; private Quantity quantity; private Money price; private OrderType orderType; public Order(Id id, Quanti

我有一个Pojo:

@Getter
@EqualsAndHashCode
public class Order {

    public enum OrderType {
        BUY, SELL
    }
    private Id id;
    private Quantity quantity;
    private Money price;
    private OrderType orderType;

    public Order(Id id, Quantity quantity, Money price, OrderType orderType) {

        Preconditions.checkNotNull(id, "id can't be null");
        Preconditions.checkNotNull(quantity, "quantity can't be null");
        Preconditions.checkNotNull(price, "price can't be null");
        Preconditions.checkNotNull(orderType, "orderType can't be null");

        this.id = id;
        this.quantity = quantity;
        this.price = price;
        this.orderType = orderType;
    }
我想做三件事:

  • 改用@AllArgsConstructor
  • 并删除构造函数
  • 但当然要保留先决条件
这可能吗


我也喜欢使用@Builder模式,我能用这种方法合并前置条件吗?

@lombok.NonNull
标记所有字段,并使用
@RequiredArgsConstructor
;应该可以。

使用
@RequiredArgsConstructor
可以适合您的情况(请参阅:)。