Home > other >  how to use lombok singular different
how to use lombok singular different

Time:12-07

@Data
@Builder
public class CarViews {
    @Singular("carViewList")
    private List<CarResponse> carViewList;
}
private CarViews prepareCarList() {
    CarResponse carResponse = CarResponse.builder().build();
    return CarViews.builder().carViewList(carResponse).build();
}

I am using singular like this, is that using right? Should I use it differently?

It does not return error, it works, but I wonder, is this using right?

CodePudding user response:

It's intended to be used like this:

@Data
@Builder
public class CarViews {
    @Singular
    private List<CarResponse> cars;
}

Lombok will automatically recognize the plural, and add a car method to the builder that'll allow you to add single CarResponse objects.

For details, see the documentation.

  • Related