一、問題的由來
最近接手了了一個合作企業的項目,前期不是我司開發的,上周做了幾天的技術對接,客戶端界面由我負責對接,從svn檢出之后,迫不及待的導入到了本地的myeclipse中,誰知立馬就出現了那個小紅叉,各種找原因,最終得以解決,現將研究過程總結如下:
二、@Override 是JDK5引入的,描述如下:
Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message.
在JDK6文檔中的描述是一模一樣!但是真正的麻煩就出在superclass 的理解上!JDK5認為Override重載是覆蓋父類方法,而JDK6則將覆蓋父類方法與實現接口方法,都定義為Override superclass。 因此只要是實現接口方法的地方寫了@Override,JDK5都會報錯
個人感覺JDK5的@Override可能是設計時候的bug吧:) 因為感覺JDK6的理解比較正確。
三、Myeclipse環境下修改@override引發的錯誤的方法
項目右鍵->build path->configure build path->java Compiler(左邊那排中) ->在右邊的Compiler compliance level 修改版本為1.6