import java.util.ArrayList;

/** Suppressing warnings. @author J. Benton */
// You can use so-called single-valued annotations
// just like regular annotations if you want (note
// how I am specifying the method name here, though
// it is unnecessary).
@SuppressWarnings(value={"unchecked"})
public class UncheckedExample {
  public void uncheckedGenerics() {
    ArrayList blahblah = new ArrayList();
    // no warning!  I suppressed it!
    blahblah.add(2);
  }
}

Example 3: Using the @SuppressWarnings annotation.

Back to Article