Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

199
Visualizações
Lombok @SuperBuilder on abstract class with generic cause error: incompatible types

I have abstract class with generic type. it has abstract toBuilder method as suggested here: Using Lombok @SuperBuilder annotation with toBuilder on an abstract class?

here is the abstract class:

@Data
@SuperBuilder(toBuilder = true)
public abstract class TenantConfItem<T extends DeepCloneable<T>> {

    private final URN urn;

    private final Long version;

    private final T configData;

    public abstract TenantConfItemBuilder<T, ?, ?> toBuilder();

    public TenantConfItem<T> copy() {
        return this.toBuilder().build();
    }
}

the subtype:

@SuperBuilder(toBuilder = true)
@EqualsAndHashCode(callSuper = true)
public class PointsExpirationByEarnedDatePolicy extends TenantConfItem<ExpirationByEarnedDate> implements Singleton {

}

here I'm using its builder:

val policyBuilder = PointsExpirationByEarnedDatePolicy.builder()
                .version(0L)
                .configData(new ExpirationByEarnedDate(retentionDays));

but I get an error for the configData:

error: incompatible types: CAP#1 cannot be converted to ?
                .configData(new ExpirationByEarnedDate(retentionDays));
                           ^
  where CAP#1,CAP#2 are fresh type-variables:
    CAP#1 extends PointsExpirationByEarnedDatePolicyBuilder<CAP#2,CAP#1> from capture of ?
    CAP#2 extends PointsExpirationByEarnedDatePolicy from capture of ?

I guess it is because the parent builder has 3 arguments with the generic (TenantConfItemBuilder<T, ?, ?>) and the sub one has 2 (PointsExpirationByEarnedDatePolicyBuilder<?, ?>). Any idea for workaround?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

@SuperBuilder(toBuilder=true) supports generic classes and refining the type parameter from the superclass in the subclass. So your classes and their annotations are fine.

However, lombok sometimes has problems inferring the correct type for val, especially when type parameters are involved.

The solution is to replace val with the actual type PointsExpirationByEarnedDatePolicyBuilder<?, ?>.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda