0
@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?

ali
  • 9
  • 2
  • "Right" is a matter of opinion. It technically works, but 'carViewList' is an extremely bad parameter name to pass the annotation IMO. Just 'car' would be better. If you call your field 'cars', which is also a better name, then 'car' will be the default anyway. – Michael Dec 06 '22 at 14:31
  • @Michael I disagree with the close vote. The intention behind how to use this is pretty clear from [the documentation](https://projectlombok.org/features/BuilderSingular) – Jorn Dec 06 '22 at 14:49
  • @Jorn How someone intends you to use something is not the same as the "right" way to use something. "Should I use it differently?" is clearly opinion based. The question was not "am I using this in exactly the way the devs expected me to?" – Michael Dec 06 '22 at 14:57

1 Answers1

0

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.

Jorn
  • 20,612
  • 18
  • 79
  • 126