Java Reference
In-Depth Information
If an element has an array type, then it is initialized with an array ini-
tializer expression. For example, an annotation to track the bug fixes
applied to a class might look like this:
@interface BugsFixed {
String[] bugIDs();
}
The intent is that as each bug is fixed, its identifier is appended to the
initializer list for bugIDs . Here's how it might be used:
@BugsFixed(bugIDs = { "457605", "532456"})
class Foo { /* ... */ }
If an array has only a single element, then you can use a shorthand
to initialize the array, dispensing with the braces around the array ele-
ments. For example, the first bug fixed in Foo could be annotated like
this:
@BugsFixed(bugIDs = "457605")
If an annotation type, like BugsFixed , has only a single element, then
naming that element value allows for some additional shorthand:
@interface BugsFixed {
String[] value();
}
The first use of BugsFixed above can now be written simply as
@BugsFixed({ "457605", "532456"})
 
Search WWH ::




Custom Search