龙目岛@Builder未检测到 Java 记录的字段
2022-09-04 07:44:26
我正在尝试使用龙目岛的@Builder实现构建器模式,但它没有检测到任何记录字段:
@Builder(builderMethodName = "internalBuilder")
public record ApiError(String title, Map<String, String> errors) {
public static ApiErrorBuilder builder(String title) {
return internalBuilder().title(title); // Cannot resolve method 'title' in 'ApiErrorBuilder'
}
}
当我将记录转换为类时,一切都按预期工作:
@Builder(builderMethodName = "internalBuilder")
public class ApiError {
private final String title;
private final Map<String, String> errors;
public ApiError(String title, Map<String, String> errors) {
this.title = title;
this.errors = errors;
}
public static ApiErrorBuilder builder(String title) {
return internalBuilder().title(title);
}
// getters
}
发生这种情况是因为龙目岛目前不能很好地处理记录吗?
我正在使用IntelliJ和龙目岛1.18.22