Possible Duplicate:
What's “@Override” there for in java?
I've never put "@Override" before a method until now. I see some code examples with it, but I don't understand its utility. I'd love some explanation.
Many thanks,
JDelage
Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message.
http://download.oracle.com/javase/6/docs/api/java/lang/Override.html
The case I like to explain its use is when overriding equals
.
This will error because equals
expects an Object
parameter:
public class Foo{
@Override
public boolean equals(Foo f){
return true;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With