Module 14: Enums and Annotations
Built-in Annotations You Should Use
Use the built-in annotations that improve safety, clarity, and compiler feedback.
Author
Java Learner Editorial Team
Reviewer
Technical review by Java Learner
Last reviewed
2026-04-17
Java version
Java 25 LTS
Learning goals
- Know what the most common built-in annotations actually do
- Use `@Override` everywhere it belongs
- Avoid lazy overuse of `@SuppressWarnings`
Annotations add metadata to code: They communicate meaning to the compiler, tools, and other developers.
@Override is the most practical one to use constantly: It prevents silent mistakes in inheritance and interface implementations.
@Deprecated warns users away from old APIs, and @SuppressWarnings should be narrow and justified: Do not use it as a broom for messy code.
Intermediate habit: If an annotation improves correctness or clarity, use it. If it hides a real problem, step back first.
Runnable examples
Override with compiler protection
class Animal {
public void speak() {}
}
class Dog extends Animal {
@Override
public void speak() {
System.out.println("Woof");
}
}Expected output
`@Override` ensures the compiler checks that `speak()` really matches a parent method.
Mini exercise
Find one overridden method in your code and add `@Override` if it is missing.
Summary
- Annotations communicate intent and metadata.
- `@Override` is especially valuable for correctness.
- `@SuppressWarnings` should stay narrow and deliberate.
Next step
Next, create your own annotations and choose the right retention policy.
Sources used