Uses for Java @override

Possible duplicate:
What does "@Override" mean for java?

Since Java 1.5, this annotation has been included in the language that will be used for methods that overwrite superclass methods.

Now, what are the changes in the method that uses this annotation to the one that does not use it? Is this just an agreement?

Assuming, obviously, both are methods that overwrite a method from its superclass ...

+6
source share
1 answer

@Override creates a compile-time check when the method is overridden. This is very useful to make sure you don't have a dumb signature problem when trying to override

This not only does the compiler check, but also documents the intent of the developer.

if you override a method but don’t use it anywhere of the type itself, someone entering the code later may know the purpose. Annotations explain her purpose.

A good IDE will effectively mark any method that overrides the method without @Override , so a combination of the two will ensure that you do what you are trying to do.

it also improves readability

+7
source

All Articles