Return to site

JAVA ANNOTATIONS: @Override & @SuppressWarnings

· java

@Override

@Override annotation informs the compiler that the element is meant to override an element declared in a superclass.

// mark method as a superclass method
  // that has been overridden
  @Override 
  int overriddenMethod() { }

@SuppressWarnings

@SuppressWarnings annotation tells the compiler to suppress specific warnings that it would otherwise generate.

// use a deprecated method and tell 
  // compiler not to generate a warning
  @SuppressWarnings("deprecation")
  void useDeprecatedMethod() {
    // deprecation warning
    // - suppressed
    objectOne.deprecatedMethod();
  }