【发布时间】:2025-12-11 16:50:01
【问题描述】:
我有类似父类的东西 (File A.java)。
每个班级都在扩展这个班级,因为每个班级都需要name。
当我在File X.java 中使用@With 函数时,它适用于.withDescription("xxx"),它是File B.java 的一部分。
但是不能将@With 函数与.withName("xxx"); 一起使用
至少 IntelliJ 没有显示 .withName("xxx")。
但是继承的.setName("xxx") 工作正常。
知道如何让它按预期工作吗?
我见过this Answer 使用@SuperBuilder,但我想在没有@Builer / @SuperBuilder 的情况下这样做
文件 A.java
@Getter
@Setter
@With
@MappedSuperclass
public class A {
public String name;
}
文件 B.java
@Getter
@Setter
@With
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class B extends A {
public String description;
}
文件 X.java
public class X {
public void x() {
var b = new B().withDescription("xxx"); // it works
b.withName("xxx"); // is NOT working.
b.setName("xxx"); // only set is working, even it's only inherited.
}
【问题讨论】:
标签: java inheritance annotations lombok intellij-lombok-plugin