empty-areknownas marker annotations becausetheymarkapplicationelementsfor
some purpose. As Listing 3-42 reveals, @Stub is used to mark empty methods (stubs).
Listing 3-42. Annotating a stubbed-out method
public class Deck // Describes a deck of cards.
public void shuffle()
// This method is empty and will presumably be filled
in with appropriate
// code at some later date.
atedbyinstantiating Stub andprefixing shuffle() 'smethodheaderwiththeresult-
ing @Stub annotation.
Note Althoughmarkerinterfaces(introducedin Chapter2 )appeartohavebeenre-
time. For example, if a class does not implement the Cloneable interface, its in-
stancescannotbeshallowlyclonedvia Object 's clone() method.If Cloneable
Althoughmarkerannotationsareuseful (@Override and @Deprecated aregood
metadata via its instances. You accomplish this task by adding elements to the type.
An element is a method header that appears in the annotation type's body. It cannot
have parameters or a throws clause, and its return type must be a primitive type (such
as int ), String , Class , an enum, an annotation type, or an array of the preceding
types. However, it can have a default value.
Listing 3-43 adds three elements to Stub .