Reputation: 6815
I am using Java1.7 and 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. Is it good practice to annotate methods in implementation class? Or do i need to annotate methods in the interface itself?
Thanks!
Upvotes: 0
Views: 184
Reputation: 1780
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
Upvotes: 1