我想在我的代码中使用lombok的@Delegate
注释。请检查下面的代码片段,它会引发一个错误:getAge()
已经定义:
public interface I {
String getName();
int getAge();
}
@Data
public class Vo {
private String name;
private long age;
}
@AllArgsConstructor
public class Adapter implements I {
@Delegate(types = I.class)
private Vo vo;
//I want to use my own code here,Because vo.getAge() returns a long,But I.getAge() expects a int
public int getAge(){
return (int) vo.getAge();
}
}
发布于 2020-06-18 02:19:59
从lombok 文档
若要非常精确地控制委托和未委派的内容,请使用方法签名编写私有内部接口,然后将这些私有内部接口指定为 ( @Delegate(types=PrivateInnerInterfaceWithIncludesList.class,excludes=SameForExcludes.class)。
这意味着要包含I
中的所有内容,但仅排除getAge
,您可以声明如下所示的额外内部接口:
private interface Exclude {
int getAge();
}
并将其传递给exclude
@Delegate(types = I.class, excludes = Exclude.class)
https://stackoverflow.com/questions/62441188
复制相似问题