Java - SuppressWarnings Annotation Type

Introduction

The SuppressWarnings is used to suppress named compiler warnings.

SuppressWarnings Annotation Type has one element named value whose data type is an array of String.

Example

The compiler generates an unchecked named warning when you use a raw type.

class A{
   public void test() {
     ArrayList list = new ArrayList();
     list.add("Hello"); // The compiler issues an unchecked warning
   }
}

The following code uses a SuppressWarnings annotation on the test() method.

It specifies two named warnings: unchecked and deprecated.


@SuppressWarnings({"unchecked", "deprecation"})
public void test() {
   ArrayList list = new ArrayList();
   list.add("Hello"); // The compiler does not issue an unchecked warning
}