给定以下代码。
@Getter
@Builder(builderClassName = "Builder", buildMethodName = "build")
public final class BusinessEvent implements BusinessPayload {
private String action, duration, outcome, provider, trackId, sequence;
@lombok.Builder.Default private Optional<String> brand, vin, externalTrackId, code = Optional.empty();
@lombok.Builder.Default private Optional<BusinessEventError> eventError = Optional.empty();
static class Builder {
BusinessEvent build() throws MissingRequiredValueException {
// Custom validation
return new BusinessEvent(action, duration, outcome, provider, trackId, sequence, brand, vin, externalTrackId, code, eventError);
}
}
}
我得到错误
java: 不能从静态上下文引用非静态变量 eventError
在这种情况下,lombok 以某种方式无法正确处理可选值?我在所有建筑商中都看到了同样的问题。intellij 插件并未将其显示为问题,但仅在我尝试构建时才显示。
我知道你不应该使用 optional 作为字段值,但在这种情况下,它使 API 更加清晰,并且构建器无论如何都不会被序列化,我们有 DTO。