Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!