我有一段代码如下
private Product createProduct(ProductParmas params){
Product product = repository.getProduct(id)
ProductBuilder.Builder builder = new ProductBuilder.Builder(); // this is a
product builder
if(product == null){
builder.location("abc").quantity(5).price(10)
if(parmas.getAvaiability() != null){
builder.availability(parmas.getAvaiability())
}
}
// I also want to set Availability on obj product, but there are no setters so I have to create an instance of ProductBuilder, copy values from product and also set availability. Is there a cleaner way to come both if product is null or not null and set availability field?
}
我还想在 obj 产品上设置可用性,但没有设置器,所以我必须创建 ProductBuilder 的实例,从产品复制值并设置可用性。如果产品为空或不为空并设置可用性字段,是否有更简洁的方法来执行此操作?
吃鸡游戏
相关分类