0

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 ?
Sandro Rey
  • 2,429
  • 13
  • 36
  • 80
  • Try annotating the `Hostel` class with a builder. If you want to see the output from lombok, read [this SO post](https://stackoverflow.com/questions/36526286/view-lombok-generated-code-in-intellij-idea). It will help you figure out the issue. – byxor Feb 19 '20 at 16:31
  • 2
    You must add `@SuperBuilder` annotation on child classes too ... check here [lombok docs](https://projectlombok.org/features/experimental/SuperBuilder) – Imtiaz Shakil Siddique Feb 19 '20 at 16:32

1 Answers1

2

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.

Michael
  • 41,989
  • 11
  • 82
  • 128