This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Importance of @override annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Importance of @override annotation" Watch "Importance of @override annotation" New topic
Author

Importance of @override annotation

Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
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
Sheriff

Joined: Sep 28, 2004
Posts: 19926
    
  43


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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43350
    
  32
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

Joined: Oct 13, 2014
Posts: 4
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

Joined: Oct 13, 2005
Posts: 43350
    
  32
Welcome to the Ranch
 
 
subject: Importance of @override annotation
 
It's not a secret anymore!