英文:
Why does the class that implements the interface have @Data and@Accessors(chain = true) that need to override the set method but not the get method?
问题
以下是您提供的代码的翻译:
我有一个接口
public interface IBaseHistory {
String getCoId();
void setPhysicalData(PhysicalData physicalData);
}
和一个实现它的类,
@Data
@Accessors(chain = true)
public class FunctionHistory implements Serializable, IBaseHistory {
private String coId;
private PhysicalData physicalData;
}
出现以下错误:
entity.FunctionHistory不是抽象的,且未覆盖抽象方法setPhysicalData(service.IBaseHistory.entity.PhysicalData)
我删除了setPhysicalData方法后,程序能够编译。
英文:
I have an interface
public interface IBaseHistory {
String getCoId();
void setPhysicalData(PhysicalData physicalData);
}
And a class that implements it,
@Data
@Accessors(chain = true)
public class FunctionHistory implements Serializable, IBaseHistory {
private String coId;
private PhysicalData physicalData;
}
Which says:
entity.FunctionHistory is not abstract and does not override the abstract method setPhysicalData(service.IBaseHistory.entity.PhysicalData)
I deleted the setPhysicalData method and the program was able to compile.
答案1
得分: 0
- 移除
@Accessors(chain = true)
。 - 更改接口。
- 将
@Accessors(chain = false)
放在你的字段上。
英文:
You used @Accessors(chain = true)
. With that will Lombok generate this:
public class FunctionHistory implements IBaseHistory {
// fields
public FunctionHistory setPhysicalData(PhysicalData physicalData) {
this.physicalData = physicalData;
return this;
}
// some more
}
This is not matching your interface.
And here are some options:
- Remove
@Accessors(chain = true)
- Change the interface
- Put
@Accessors(chain = false)
onto your field.
And here are the related Lombok docs:
https://projectlombok.org/features/experimental/Accessors
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论