[英]annotating methods in implementation classes or interfaces?
I am using Java1.7 and spring3. 我正在使用Java1.7和spring3。
I have below classes. 我有以下课程。
public interface MyInterface{
String getResult();
}
public class MyInterfaceImpl implements MyInterface{
@MyCustomAnnotation
public String getResult(){
//some logic
}
}
I annotated method in Impl class. 我在Impl类中注释了方法。 Is it good practice to annotate methods in implementation class? 在实现类中注释方法是否是一种好习惯? Or do i need to annotate methods in the interface itself? 还是我需要在接口本身中注释方法?
Thanks! 谢谢!
Classes don't inherit the annotation from interfaces, so you should be really careful using annotations on interfaces. 类不会从接口继承注释,因此您应该非常小心在接口上使用注释。
Here is an example of what can happen if you are not careful: 这是一个示例,如果您不小心会发生什么:
http://kim.saabye-pedersen.org/2013/05/spring-annotation-on-interface-or-class.html http://kim.saabye-pedersen.org/2013/05/spring-annotation-on-interface-or-class.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.