Last Updated: June 6, 2026
Built-in annotations like @Override and @Deprecated cover a narrow slice of what annotations can do. The real power shows up with custom annotations. A custom annotation marks methods, fields, parameters, or whole classes with information that frameworks, build tools, or your own code can read at compile time or at runtime. This chapter covers the mechanics: how to declare an annotation with @interface, what kinds of elements it can have, how default values work, what marker and single-element annotations look like, and how the five meta-annotations (@Target, @Retention, @Documented, @Inherited, @Repeatable) shape what an annotation can do.