• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Importance of @override annotation

 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please can someone explain to me the importance of @override annotation because i can't really see its importance if we have a Class that contains a method that overrides another method in the super class, why the need for the @override annotation
 
Henry Wong
author
Marshal
Pie
Posts: 21016
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It's great for catching spelling errors. For example, if you tried to override the hashCode() method, and accidently type hashcode() instead, the compiler will complain.

Henry
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
It's great for catching spelling errors.
And it's got a spelling error in It's @Override, not @override! Remember Java is case-sensitive, and the tiniest spelling error can cause no end of problems.
 
ganesh swamypillai
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check in this link: Importance of Override annotation.

Also check StackOverflow

Basically, consider creating a set of employee objects and equals() method is not having override annotation, then set will contain duplicate entries.

Compiler will not invoke employee's equals() method, but equals() of Object.

Suppose, you intended to override a method, but suppose your method's signature is wrong compared to superclass, then compiler will flag, if @Override annotation is used.



 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic