I’ve been very pleased with the @Override annotation in Java 5.0. If you’re not familiar with what does, it ensures that a method is overriding a method in a parent class.

For example:

class A {
  public void foo() {}
}

class B extends A {
  @Override public void foo() {}
  @Override public void bar() {}
}

In this example, the compilation of class B will fail because the method bar() is not overriding a method in class A. Additionally, if the method foo() in class is removed or if its argument list changes, class B will fail when trying to compile its method foo().

When I first saw this annotation, I thought it was of little value but I have since changed my tune. This annotation is extremely useful for refactoring. I have burned myself a couple of times when refactoring a parent class method’s argument list and forgetting to refactor the overriding methods. This annotation helps me from getting burned.