You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Lombok builder on generics gives compilation error, related with wrong types:
public class Main {
public static abstract class Animal {
}
public static class Dog extends Animal {
}
@Getter
@Setter
public static class SimpleBuilder<ANIMAL extends Animal> {
private ANIMAL animal;
}
@Getter
@lombok.Builder
public static class LombokBuilder<ANIMAL extends Animal> {
private ANIMAL animal;
}
public static void main(String[] args) {
//COMPILES OK:
final SimpleBuilder<Dog> simpleBuilder = new SimpleBuilder<>();
simpleBuilder.setAnimal(new Dog());
//COMPILATION ERROR:
final LombokBuilder<Dog> lombokBuilder = LombokBuilder.builder().animal(new Dog()).build();
}
}
The problem has to do with the type inference. It doesn't carry as far as you seem to think. The call to LombokBuilder.builder() does not have any clue on what you're going to put in. So you need to help the compiler a bit to make it compile:
Lombok version: 1.16.18
Using Lombok builder on generics gives compilation error, related with wrong types:
LombokBuilder gives upcoming error:
The text was updated successfully, but these errors were encountered: