Because it provides compile-time assurance that you actually *are* overriding a method from a superclass. Thus you avoid scenarios where you remembered the method signature incorrectly and accidentally overloaded the method rather than overriding. Additionally, you get some assurance that you can avoid behavior changes in the case that the superclass method signature changes out from underneath you (like when the part-time intern refactors your hierarchy without telling anyone).
The first example is easily taken care of with a good IDE showing you when a method is overloaded or overridden, eliminating the need for @Overide in that case. Although usefull in the second case, the @Override annotation remains, to my opinion, a necessary scar on the face of java code.
Comments
dzonelurker replied ago:
Why are people using those silly '@Override' annotations in their programs?
daniel replied ago:
Because it provides compile-time assurance that you actually *are* overriding a method from a superclass. Thus you avoid scenarios where you remembered the method signature incorrectly and accidentally overloaded the method rather than overriding. Additionally, you get some assurance that you can avoid behavior changes in the case that the superclass method signature changes out from underneath you (like when the part-time intern refactors your hierarchy without telling anyone).
Vikstar replied ago:
The first example is easily taken care of with a good IDE showing you when a method is overloaded or overridden, eliminating the need for @Overide in that case. Although usefull in the second case, the @Override annotation remains, to my opinion, a necessary scar on the face of java code.
amalter replied ago:
Man, you should spend less time lurking at dzone and more time coding
Ignacio Coloma replied ago:
If you ever try a refactor hell that affects +100 classes, you will find @Override useful.
After that, you even feel good when you see it around.
Voters For This Link (16)
Voters Against This Link (1)