我有一个类似于父类(File A.java
)的东西。
每个类都在扩展这个类,因为每个类都需要name
。
当我在File X.java
中使用@With
函数时,它适用于作为File B.java
一部分的.withDescription("xxx")
。
但是不可能将@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.
}
发布于 2020-11-15 17:23:34
您需要将@AllArgsConstructor
添加到A
https://stackoverflow.com/questions/64847166
复制相似问题