Do we really need @Override and so on when code Java? [duplicate]

It is not necessary, but it is highly recommended. It keeps you from shooting yourself in the foot. It helps prevent the case when you write a function that you think overrides another one but you misspelled something and you get completely unexpected behavior.


what the functionality of adding @Override

It lets the compiler double-check for you when you say (by annotating) that a specified method is supposed to override a superclass method (or implement an interface method in Java 6 or later). If the method does not, in fact, override a superclass method (or implement an interface method), the compiler will flag this as an error. This often indicates that you have a typo in the method name or made a mistake in the method signature.

Do we really need @Override

Need it? Absolutely not, but its such a cheap way to

  • conveys explicitly to human reader that this is an overriding method, and
  • catches a bug at compile time that could take at least a few brain cycles to catch at run-time once you even know to look for it

... and even cheaper when your IDE is helping you include it ...