Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it compulsory to annotate inherited methods with @Override? [duplicate]

Possible Duplicate:
When do you use Java's @Override annotation and why?

Newbie question - I'm writing my first Android app (its my 2nd Java app). I noticed that in examples the onCreate() method has the @Override annotation, but I haven't used that annotation and it seems to work fine.

Is it just good practice to use the @Override annotation or am I setting myself up for problems. What about the other inherited methods - onPause etc?

like image 525
Yoav Avatar asked Dec 20 '11 15:12

Yoav


2 Answers

The @Override annotation allows the compiler to ensure you're actually overriding a method or implementing an interface method (Java 6+). This can avoid one class of simple errors, like screwing up a method signature and not actually overriding what you think you are.

It's not mandatory, but it's a good idea, and is free help from the compiler.

like image 161
Dave Newton Avatar answered Sep 29 '22 07:09

Dave Newton


It's only good practice, which

  • helps developers see which methods are overriden
  • lets the compiler check that the signature is compliant with the overriden method
like image 22
Johan Sjöberg Avatar answered Sep 29 '22 06:09

Johan Sjöberg