首先来看源码: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注解做用:翻译