Search code examples
javadefault-valuebuilderlombok

Lombok: Singular Builder and a default value


Lombok version is 1.18.0.

I have @Builder set on class level.

When I try to set a default value for a list variable:

@Builder.Default
@Singular
private List<Class<? extends Exception>> retryTriggers = Lists.newArrayList(Exception.class);

I got an error:

Error:(46, 5) java: @Builder.Default and @Singular cannot be mixed.

Besides writing the builder myself, is there another way to do this?


Solution

  • I would suggest replacing the generated builder() method with the following one:

    @Builder
    class ExceptionHandler {
        @Singular
        private final List<Class<? extends Exception>> retryTriggers;
    
        public static ExceptionHandlerBuilder builder() {
            return new ExceptionHandlerBuilder().retryTrigger(Exception.class);
        }
    }