Search code examples
javabuilderlombokintellij-lombok-plugin

capture of ? using Lombok builder


I have this class

public class Hostel extends Hotel<Book> {
}

and this other one

@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(of = { "id" })
@SuperBuilder(toBuilder = true)
@JsonInclude(NON_NULL)
public class Hotel<T>  {
...
}

but when I do

Hostel hostel = Hostel.builder().build();

I got this compilation error

 Required type: Hostel
Provided:
capture of ?

Solution

  • You don't have any annotations on Hostel. Hostel.builder() is really a masquerading Hotel.builder().

    So the assignment would have to be

    final Hotel<?> build = Hostel.builder().build();
    

    Or more accurately (making static methods subject to inheritance was IMO a mistake)

    final Hotel<?> build = Hotel.builder().build(); 
    

    You probably want to add some Lombok annotations to the child class.