Quick revision
The short answer
@Override makes the compiler fail if the method does not override or implement a supertype method; @Deprecated marks an element as discouraged and makes the compiler warn at every use, with since and forRemoval attributes since Java 9; @SuppressWarnings silences named compiler warnings such as unchecked or deprecation in its scope; @FunctionalInterface makes the compiler fail unless the interface has exactly one abstract method; and @SafeVarargs suppresses heap pollution warnings for a generic varargs method that cannot be overridden. All of them change what the compiler checks or reports, and none of them changes how the code behaves at run time.
What to remember
In this answer, we went through the five built-in annotations. @Override and @FunctionalInterface make the compiler fail when a method does not override anything or an interface does not have exactly one abstract method. @Deprecated, with since and forRemoval since Java 9, makes the compiler warn at every use, with a stronger removal warning when forRemoval is true. @SuppressWarnings and @SafeVarargs silence warnings, the latter only on methods that cannot be overridden. All of them are compiler checks or warning controls, and none of them changes run-time behaviour.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
@Override makes the compiler fail if the method does not override or implement a supertype method; @Deprecated marks an element as discouraged and makes the compiler warn at every use, with since and forRemoval attributes since Java 9; @SuppressWarnings silences named compiler warnings such as unchecked or deprecation in its scope; @FunctionalInterface makes the compiler fail unless the interface has exactly one abstract method; and @SafeVarargs suppresses heap pollution warnings for a generic varargs method that cannot be overridden. All of them change what the compiler checks or reports, and none of them changes how the code behaves at run time.
Why this question is asked
These five annotations come with the JDK, and we see them every day, often added by the IDE without a second thought. Interviewers ask about them because each one is a small contract with the compiler, and knowing exactly what each one checks tells us when they protect us and when they are only decoration. In this answer, we will go through each annotation with an example of what the compiler does with it, look at which of them are kept in the class file, and answer the two classic follow-ups about @Override and @Deprecated(forRemoval = true).
1A Quick Recap: What a Built-In Annotation Is
An annotation is a piece of metadata attached to code, written with an @ sign. By itself it does nothing; some tool has to read it. For these five, that tool is mainly the Java compiler. They live in java.lang, so we never need to import them, and each one either asks the compiler to check something or controls which warnings it prints.
2@Override: Make Sure We Really Override
@Override on a method tells the compiler: this method is meant to override a method of a superclass or implement a method of an interface. If it does not, because of a typo, a wrong parameter type, or because the parent method was renamed, compilation fails.
Without the annotation, toSting() would compile as a brand new method, and toString() would silently keep returning Order@1b6d3586. That is why @Override is valuable when a superclass signature changes later: every subclass method marked @Override that no longer matches becomes a compile error, instead of quietly turning into an unused overload.
3@Deprecated: Discourage Use and Warn Callers
@Deprecated marks a class, method or field that callers should stop using. Code that uses it still compiles, but the compiler prints a deprecation warning at every use. Since Java 9 it has two attributes: since, a string naming the version in which it was deprecated, and forRemoval, a boolean saying it will be removed in a future version.
forRemoval = true makes the compiler issue a removal warning instead of an ordinary deprecation warning. Removal warnings belong to a separate category: they are shown by default, and @SuppressWarnings("deprecation") does not silence them; only @SuppressWarnings("removal") does. So it adds a stronger, harder-to-ignore signal that the API will actually disappear.
4@SuppressWarnings, @FunctionalInterface and @SafeVarargs
@SuppressWarnings takes the names of warnings to silence in the annotated element: a method, a class, or even a single local variable declaration. Common names are unchecked, deprecation, removal and rawtypes; others depend on the compiler. Putting it on the smallest possible scope keeps it from hiding unrelated problems.
@FunctionalInterface on an interface tells the compiler that it is meant to be used with lambdas, so it must have exactly one abstract method. Default and static methods do not count, and neither do methods that match public methods of Object, such as equals. If someone later adds a second abstract method, the interface itself fails to compile, instead of every lambda that uses it.
@SafeVarargs is a promise by the author of a generic varargs method that the method does not do anything unsafe with its varargs array, which removes the heap pollution warning at every call site. Because the promise cannot be checked for subclasses, it is only allowed on methods that cannot be overridden: static methods, final instance methods, constructors, and since Java 9 private instance methods.
5Which Ones Change What the Compiler Does?
All five do, in one way or another. @Override and @FunctionalInterface add compile errors; @Deprecated adds warnings at uses; @SuppressWarnings and @SafeVarargs remove warnings. None of them changes the generated bytecode's behaviour: a program behaves exactly the same at run time if we delete them, as long as it still compiles.
They do differ in retention, which is how long the annotation survives. @Override and @SuppressWarnings are SOURCE annotations, discarded after compilation. @Deprecated, @FunctionalInterface and @SafeVarargs are RUNTIME annotations, kept in the class file and visible through reflection. That is why the compiler can warn about a deprecated method in a library jar it only has as a class file, but even then the annotation is information, not behaviour.
| Annotation | Compiler effect | Retention |
|---|---|---|
@Override | Error if nothing is overridden or implemented | SOURCE |
@Deprecated | Warning at each use; removal warning if forRemoval | RUNTIME |
@SuppressWarnings | Silences named warnings in its scope | SOURCE |
@FunctionalInterface | Error unless exactly one abstract method | RUNTIME |
@SafeVarargs | Silences heap pollution warnings at call sites | RUNTIME |
6Follow-up questions
Why is @Override valuable when a superclass method signature changes later?
Because the change turns every subclass override into a compile error. Suppose Parent.price(int qty) becomes price(long qty). A subclass method price(int qty) without @Override would still compile as a separate overload, and callers would silently start getting the parent's behaviour. With @Override, the build fails and points at every method that needs updating.
What does @Deprecated(forRemoval = true) add over plain @Deprecated?
It says the element will actually be removed, not just discouraged. The compiler issues a removal warning, a separate category from ordinary deprecation warnings, which is shown by default and is not silenced by @SuppressWarnings("deprecation"). Tools such as jdeprscan also report it, and it tells callers to plan the migration now.
Is a lambda allowed for an interface without @FunctionalInterface?
Yes. Any interface with exactly one abstract method can be the target of a lambda. The annotation only makes the intent explicit and lets the compiler protect it from future changes, which is why it is worth adding on interfaces we design for lambdas.
7Conclusion
In this answer, we went through the five built-in annotations. @Override and @FunctionalInterface make the compiler fail when a method does not override anything or an interface does not have exactly one abstract method. @Deprecated, with since and forRemoval since Java 9, makes the compiler warn at every use, with a stronger removal warning when forRemoval is true. @SuppressWarnings and @SafeVarargs silence warnings, the latter only on methods that cannot be overridden. All of them are compiler checks or warning controls, and none of them changes run-time behaviour.
Open with
All five are aimed at the compiler. @Override says this method must override or implement a supertype method, and if it does not, for example because of a typo or because the parent's signature changed, compilation fails instead of silently creating a new overload. @Deprecated marks something callers should stop using, and the compiler warns at every use; since Java 9 it has since, for the version, and forRemoval.
Then, if they want more
With forRemoval true the compiler gives a removal warning, which is a separate category that shows by default and is not silenced by suppressing deprecation. @SuppressWarnings silences named warnings like unchecked or deprecation, and I keep it on the smallest scope possible, even a single variable. @FunctionalInterface makes the compiler check that the interface has exactly one abstract method, so someone adding a second method breaks the interface rather than every lambda.
And @SafeVarargs is the author's promise that a generic varargs method does not misuse its array, which removes heap pollution warnings at call sites; it is only allowed where the method cannot be overridden, so static, final, private methods and constructors.
So they all change what the compiler checks or reports, but none of them changes run-time behaviour. @Override and @SuppressWarnings are not even kept in the class file.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 9
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What do @Override, @Deprecated, @SuppressWarnings, @FunctionalInterface and @SafeVarargs...": https://scrivio-interview-library.netlify.app/java/annotations/91464a7306/