Java Reference
In-Depth Information
// ...
}
Notice how the initialization expression for an element of an annotation
type uses the annotation syntax. In this case
@Revision
initializes the re-
vision element with the default values for
major
and
minor
. When
Foo
is
later edited, the revision element would be changed accordingly, for ex-
ample:
@ClassInfo (
created = "Jan 31 2005",
createdBy = "James Gosling",
lastModified = "Feb 9 2005",
lastModifiedBy = "Ken Arnold",
revision = @Revision(major = 3)
)
public class Foo {
// ...
}
This updates the revision to be 3.0, by specifying the major value and
again allowing the minor value to default to 0.
An annotation type can have zero elements, in which case it is called
a
marker annotation
similar to a marker interface. For example, the an-
notation type
java.lang.Deprecated
is a marker annotation that identifies
a program element that should no longer be used. The compiler can is-
sue a warning when a program element annotated with
@Deprecated
is
used, as could an annotation-aware development environment.
If an annotation type has but a single element, then that element should
be named
value
. This permits some syntactic shorthand that is described
in the next section.