Item 36: Consistently use the Override annotation

1.  Override annotation can be used only on method declarations, and it indicates that the annotated method declaration overrides a declaration in a supertype. If you consistently use this annotation, it will protect you from a large class of nefarious bugs.

 

2.  You should use the Override annotation on every method declaration that you believe to override a superclass declaration.

 

3.  If you enable the appropriate code inspection, the IDE will generate a warning if you have a method that doesn’t have an Override annotation but does override a superclass method. If you use the Override annotation consistently, these warnings will alert you to unintentional overriding. These warnings complement the compiler’s error messages, which alert you to unintentional failure to override. Between the IDE and the compiler, you can be sure that you’re overriding methods everywhere you want to override them and nowhere else.

 

你可能感兴趣的:(annotation,override)