Why Use the @Override Annotation?
One of the most useful annotations Java 1.5 introduced is undoubtedly @Override. Use it whenever you override a method declared by a superclass. If the compiler can't find a method with the same signature in the superclass, it reports a compilation error straight away. Some people expect only a warning. The annotation protects your code from bugs that can be hard to detect.
public class Predek {
public void doSomething() {
}
}
public class Potomek extends Predek {
@Override
public void doSomething() {
}
}
Suppose the method signature changes because you add a parameter, either in the superclass or in the subclass. In Eclipse, the compiler reports “The method doSomething() of type Potomek must override or implement a supertype method.”
Related articles
Related CZ Podcast episodes
- #3 · Java 6 SE, Vývoj webových aplikací
Dagi and Filemon discuss Java 6 and web application frameworks. · Czech audio
- #1 · Vývojová prostředí v Javě
The first CZ Podcast episode looks at Java development environments. · Czech audio