Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda