首先來看源碼:less
1 /** 2 * Indicates that a method declaration is intended to override a 3 * method declaration in a supertype. If a method is annotated with 4 * this annotation type compilers are required to generate an error 5 * message unless at least one of the following conditions hold: 6 * 7 * <ul><li> 8 * The method does override or implement a method declared in a 9 * supertype. 10 * </li><li> 11 * The method has a signature that is override-equivalent to that of 12 * any public method declared in {@linkplain Object}. 13 * </li></ul> 14 * 15 * @author Peter von der Ahé 16 * @author Joshua Bloch 17 * @jls 9.6.1.4 @Override 18 * @since 1.5 19 */ 20 @Target(ElementType.METHOD) 21 @Retention(RetentionPolicy.SOURCE) 22 public @interface Override { 23 }
源碼中註釋翻譯以下:ide
指示方法聲明旨在覆蓋超類型中的方法聲明。若是用這種註釋類型的編譯器對方法進行註釋,則須要生成錯誤消息,除非至少知足下列條件之一:ui
(以上翻譯來自有道)this
簡單來講來講就是:加了此註解的方法,表示此方法是一個覆寫的方法,若是不知足覆寫會報錯。idea
idea報錯以下:spa
總結@Override註解做用:翻譯