Java Reference
In-Depth Information
fields.
*/
@Deprecated
String name;
String firstName;
String lastName;
public static void main(String[] args)
{
Employee emp = new Employee();
emp.name = "John Doe";
}
}
Listing 3-38 declares an Employee class with a name field that has been deprec-
ated. Although Employee 's main() method refers to name , the compiler will sup-
press a deprecation warning because the deprecation and reference occur in the same
class.
Suppose you refactor this listing by introducing a new UseEmployee class and
moving Employee 's main() methodtothisclass. Listing3-39 presentstheresulting
class structure.
Listing 3-39. Referencing a deprecated field from within another class declaration
class Employee
{
/**
* Employee's name
* @deprecated new version uses firstName and lastName
fields.
*/
@Deprecated
String name;
String firstName;
String lastName;
}
class UseEmployee
{
Search WWH ::




Custom Search