Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@override annotation

Tags:

java

Do I need to put @Override annotation when I implement an interface (not override an abstract class)?

And what does @Override annotation achieve?

like image 522
michael Avatar asked Sep 11 '25 07:09

michael


1 Answers

In Java 5, you must not add @Override when implementing a method inherited from an interface, in Java 6, you should (or you'll get a compiler warning).

@Override asserts that a method is intended to override something, and will cause the compiler to notify you should this not or no longer be the case, for instance because the method you are overriding has been renamed.

like image 184
meriton Avatar answered Sep 12 '25 22:09

meriton