[英]Java + Lombok + Guava + Validation
我有這個 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;
}
我想做三件事:
這可能嗎?
我也喜歡使用 @Builder 模式,我可以將前提條件與這種方法結合起來嗎?
用@lombok.NonNull
標記所有字段並使用@RequiredArgsConstructor
; 應該這樣做。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.