Java Reference
In-Depth Information
Listing 3-43. Adding three elements to the Stub annotation type
public @interface Stub
{
int id(); // A semicolon must terminate an element de-
claration.
String dueDate();
String developer() default "unassigned";
}
The id() elementspecifiesa32-bitintegerthatidentifiesthestub.The dueDate()
element specifies a String -based date that identifies when the method stub is to be
implemented.Finally, developer() specifiesthe String -basednameofthedeve-
loper responsible for coding the method stub.
Unlike id() and dueDate() , developer() isdeclaredwitha default value,
"unassigned" . When you instantiate Stub and do not assign a value to deve-
loper() inthatinstance,asisthecasewith Listing3-44 , thisdefaultvalueisassigned
to developer() .
Listing 3-44. Initializing a Stub instance's elements
public class Deck
{
@Stub
(
id = 1,
dueDate = "12/21/2012"
)
public void shuffle()
{
}
}
Listing3-44 revealsone @Stub annotationthatinitializesits id() elementto 1 and
its dueDate() elementto "12/21/2012" .Eachelementnamedoesnothaveatrail-
ing () ,andthecomma-separatedlistoftwoelementinitializersappearsbetween ( and
) .
 
 
Search WWH ::




Custom Search