Java Reference
In-Depth Information
public static void main(String[] args)
{
Employee emp = new Employee();
emp.name = "John Doe";
}
}
Ifyouattempttocompilethissourcecodeviathe
javac
compilertool,youwilldis-
cover the following messages:
Note: Employee.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Youwillneedtospecify
-Xlint:deprecation
asoneof
javac
'scommand-line
arguments(asin
javac -Xlint:deprecation Employee.java
)todiscover
the deprecated item and the code that refers to this item:
Employee.java:17: warning: [deprecation] name in Employee
has been deprecated
emp.name = "John Doe";
^
1 warning
@SuppressWarnings
annotations are useful for suppressing deprecation or un-
checkedwarningsviaa
"deprecation"
or
"unchecked"
argument.(Unchecked
warnings occur when mixing code that uses generics with pre-generics legacy code. I
discuss generics and unchecked warnings later in this chapter.)
argument to suppress the compiler's deprecation warnings when code within the
UseEmployee
class's
main()
method accesses the
Employee
class's
name
field.
Listing 3-40.
Suppressing the previous deprecation warning
class Employee
{
/**
* Employee's name
* @deprecated new version uses firstName and lastName
fields.
*/
@Deprecated