[英]Java + Lombok + Guava + Validation
I have this Pojo:我有这个 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;
}
I wish to do three things:我想做三件事:
Is this possible?这可能吗?
I also like to use @Builder pattern, can I incorporate Preconditions with this approach?我也喜欢使用 @Builder 模式,我可以将前提条件与这种方法结合起来吗?
Mark all fields with @lombok.NonNull
and use @RequiredArgsConstructor
;用
@lombok.NonNull
标记所有字段并使用@RequiredArgsConstructor
; that should do it.应该这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.