我正在尝试将日志添加到我的接口默认方法中。例如:
@Slf4j // not allowed
interface MyIFace {
default ThickAndThin doThisAndThat() {
log.error("default doThisAndThat() called");
}
}
问题是我得到了:
@Slf4j仅对类和枚举是合法的。
什么是正确的方法来处理这件事?
发布于 2020-10-17 15:40:29
您不能在这里使用Lombok,因为注释会生成:
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(YourClass.class);
不能在接口中使用私有关键字。
解决办法是直接编写
interface MyIFace {
org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MyIFace.class);
default ThickAndThin doThisAndThat() {
log.error("default doThisAndThat() called");
}
}
https://stackoverflow.com/questions/64404180
复制相似问题