Java Reference
In-Depth Information
String name;
String firstName;
String lastName;
class UseEmployee
public static void main(String[] args)
Employee emp = new Employee(); = "John Doe";
Note Asamatterofstyle,youshouldalwaysspecify @SuppressWarnings on
Finally, @SafeVarargs annotations are useful for asserting that the body of the
annotated method or constructor does not perform potentially unsafe operations on its
I present generics later in this chapter.
Declaring Annotation Types and Annotating Source Code
Java supplies many annotation types as well as Override , Deprecated , Sup-
pressWarnings , and SafeVarargs . Java also lets you declare your own types.
Youdeclareanannotationtypebyspecifyingthe @ symbol,immediatelyfollowedby
reservedword interface ,followedbythetype'sname,followedbyabody.Forex-
ample, Listing 3-41 uses @interface to declare an annotation type named Stub .
Listing 3-41. Declaring the Stub annotation type
public @interface Stub
Search WWH ::

Custom Search