在调用 build() 之前,@Builder 对象的 class 类型是什么?

What is the class type of a @Builder object before calling build()?

我以前做过,但忘记了,无法在网上轻松找到答案。

假设我在 POJO 上安装了 lombok

@Builder
@NoArgsConstructor
class Car {
    private int gallons;
    private int wheels;
    private String name;
}

并且我想在某些逻辑中使用构建器符号

public Car getCar(boolean isNew) {

    <I dont know what type to put here> carBase = Car.builder().wheels(4);

    if(!isNew) {
        return carBase.gallons(10).build();
    }
    else {
        return carBase.gallons(0).build();
    }
}

我应该用什么类型填写?

好的,所以我实际上 运行 遇到了这个错误 ,它破坏了我的 @Builder class。

显然 lombok 将在 class 中生成静态嵌套 class,并用 @Builder 注释,称为 <classname>Builder,因此要回答我最初的问题,将有一个有效的 class 称为 Car.CarBuilder.