Which annotation is used to suppress compiler warnings in Java?
Answer
@SuppressWarnings
Answer
@SuppressWarnings
The Java annotation used to suppress compiler warnings is @SuppressWarnings.
It tells the compiler to omit specified warnings for the annotated declaration and, where applicable, elements contained within it. A common example is @SuppressWarnings("unchecked"), used when legacy code or a type conversion produces an unchecked-operation warning. Multiple categories can be supplied in an array, such as @SuppressWarnings({"unchecked", "deprecation"]).
The annotation belongs to java.lang, so it does not require an import. It was introduced in Java 5, alongside the language's generics and annotation features. Its retention policy is SOURCE, meaning the annotation is intended for compiler processing and is not normally retained in the class file for runtime inspection.
@SuppressWarnings does not repair the underlying issue; it only hides the selected diagnostic. Good practice is to apply it to the smallest declaration that needs it and to document why it is safe. @Deprecated marks outdated APIs, @Override checks inheritance intent, and @FunctionalInterface validates an interface design.
Source: Wikipedia · fact-checked Aug. 2026