Setters AND ( not OR or VS ) builder patterns

后端 未结 6 1050
一整个雨季
一整个雨季 2021-02-05 23:07

I have a situation where I use a builder pattern for constructing an object. Best example to give is the pizza code

public class Pizza {
  private int size;
  pr         


        
6条回答
  •  鱼传尺愫
    2021-02-05 23:29

    you can use @Builder(toBuilder = true).

    @Builder(toBuilder = true)
    class Pizza {
    int val;
    }
    
    Pizza ob = Pizza.builder().val(10)build();
    
    Pizza newObj = ob.toBuilder().val(11).build();
    

    Ref : https://projectlombok.org/features/Builder

提交回复
热议问题