注解应该写在哪?

今天遇到了这样的情况!

public interface FlowService {
    @FlowOperationLog
    FlowDTO createFlow(FlowDTO flowDTO);
    @FlowOperationLog
    FlowDTO updateFlowStatus(FlowDTO flowDTO);
}

其中@FlowOperationLog是flow类的日志注解,而我的大哥让我把该注解写在接口上,但我写上之后,发现该注解无法生效。

SO----->

  • 注解只能加在具体的方法体上!

但有一个例外:

@PlanOperationLog
default T process(T t) {
    preModify(t);
    t = modify(t);
    postModify(t);
    return t;
}

当接口中的方法经过重新编排后,加了default关键字,那么注解就可以生效!

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务