[英]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.