I would like to use lombok's @Delegate annotations in the my code.
Please check code snippet below and it throws an error saying :getAge() is already defined :
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();
}
}
From the lombok documentation:
To have very precise control over what is delegated and what isn't, write private inner interfaces with method signatures, then specify these private inner interfaces as types in
@Delegate(types=PrivateInnerInterfaceWithIncludesList.class, excludes=SameForExcludes.class).
Which means that to include everything in I, but exclude only getAge, you can declare an extra inner interface like this:
private interface Exclude {
int getAge();
}
and pass it to exclude:
@Delegate(types = I.class, excludes = Exclude.class)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With