[英]annotating methods in implementation classes or interfaces?
我正在使用Java1.7和spring3。
我有以下课程。
public interface MyInterface{
String getResult();
}
public class MyInterfaceImpl implements MyInterface{
@MyCustomAnnotation
public String getResult(){
//some logic
}
}
我在Impl类中注释了方法。 在实现类中注释方法是否是一种好习惯? 还是我需要在接口本身中注释方法?
谢谢!
类不会从接口继承注释,因此您应该非常小心在接口上使用注释。
这是一个示例,如果您不小心会发生什么:
http://kim.saabye-pedersen.org/2013/05/spring-annotation-on-interface-or-class.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.