innerbuilder icon indicating copy to clipboard operation
innerbuilder copied to clipboard

Support for Optionals

Open adnang opened this issue 10 years ago • 1 comments

If I have some class with final optional variables, e.g

public final class ProductData {
    private final String code;
    private final String category;
    private final Optional<PriceData> price;
    //... getters ...
}

I want a option to create builder method that takes a PriceData instance and sets price to:

public ProductDataBuilder withPrice(PriceData price){
    this.price = Optional.ofNullable(price);
    return this;
}

This will make building classes with optional variables much smoother as we do not need to pre-wrap the arguments.

adnang avatar Mar 21 '15 14:03 adnang

@adnang Optional type for a field is not recommended;

douglarek avatar Oct 18 '17 09:10 douglarek