The @Override annotation.

Figure 512. Overriding Object.toString() Slide presentation
public class Shape {

  double x, y;
 ...
  @Override  // Promise: Method overrides Object.toString();
  public String toString() {
    return "(" + x + "|" + y + ")";
  }
}

Figure 513. @Override: Compile time error detection Slide presentation
public class Shape {

  double x, y;
 ...
  @Override  // Error: method does not override a method from a supertype
  public String tostring() { // Error: Should be toString
    return "(" + x + "|" + y + ")";
  }
}

Explanation: The given method actually does not override Object.toString().


Figure 514. Remarks on @Override Slide presentation
  • Helps avoiding programming errors

  • Irrelevant with respect to runtime behavior