View RSS Feed

My Java Tips

Override annotation

Rate this Entry
by , 11-01-2011 at 07:02 PM (614 Views)
Tiger provides many built-in annotation types and Override is one of them. Override should be used only on methods to indicate that the annotated method is overriding a method in a superclass. An example is presented below:





Java Code:
package com.domian.a.test;

public class OverrideTester {

  public OverrideTester() { }

  @Override
  public String toString() {
    return super.toString() + " [Override Tester Implementation]";
  }

  @Override
  public int hashCode() {
    return toString().hashCode();
  }
}
In the above example, the @Override annotation annotates two methods toString() and hashCode(). Annotations indicate that these methods are override versions of the methods from the OverrideTester class's superclass which is java.lang.Object.

Submit "Override annotation" to Facebook Submit "Override annotation" to Digg Submit "Override annotation" to del.icio.us Submit "Override annotation" to StumbleUpon Submit "Override annotation" to Google

Tags: None Add / Edit Tags
Categories
Annotations

Comments