What does "@Override " mean before declaring a method?


What does "@Override" mean before declaring a method?

Author: αλεχολυτ, 2010-10-15

2 answers

In fact, the @Override annotation indicates that next we are going to override the base class method.
At the same time, if the base class does not have a method with a similar signature, we will get a compiler warning that although we were going to redefine something, in fact this did not happen.

This is the end of the annotation action.

Thus, the annotation does not affect the fact that the method is redefined in any way-if the signatures match with by the base class method, it will already be overridden, regardless of the presence or absence of this annotation. The annotation only serves to control the success of the action when building the project.

If this annotation is missing and the signatures do not match (as a result of an error) with the method that we were going to redefine, a terrible thing will happen - a very subtle error when you think that you should be redefining, but in fact you have a separate independent method that most likely, it is not executed at all. At the same time, the compiler believes that from its point of view everything is fine - you want your own method in the descendant class-no problem. And is silent.

 124
Author: pavlofff, 2017-11-18 21:52:02

The @Override annotation before the method declaration means that the method overrides the method declaration in the base class.

 27
Author: stanislav, 2015-11-19 09:40:18