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?

huangapple go评论53阅读模式
英文:

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

  1. 移除 @Accessors(chain = true)
  2. 更改接口。
  3. @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:

  1. Remove @Accessors(chain = true)
  2. Change the interface
  3. Put @Accessors(chain = false) onto your field.

And here are the related Lombok docs:
https://projectlombok.org/features/experimental/Accessors

huangapple
  • 本文由 发表于 2023年4月4日 11:04:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75925211.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定