Elements
Annotation interfaces can contain any number of elements.
@interface Todo {
String description();
}
These are declared in the same way as methods in an interface, save for some important restrictions.
The method should take no arguments.
@interface Todo {
// Cannot take arguments
String description(int x);
}
And the return value needs to be one of a few built-in types like Class
, String
, int
, boolean
, etc.1, an enum
, or an array of one of those.
enum Priority {
HIGH,
LOW
}
class PersonInCharge {}
@interface Todo {
// String ✅
String description();
// int ✅
int someNumber();
// boolean ✅
boolean isImportant();
// Class ✅
Class<?> someRelatedClass();
// Arrays ✅
String[] notes();
// Enums ✅
Priority priority();
// Other Classes ❌
PersonInCharge personInCharge();
}
1
You can find the full list here. It is a short list.