Java Reference
In-Depth Information
public static void main(String[] args)
Employee emp = new Employee(); = "John Doe";
Ifyouattempttocompilethissourcecodeviathe javac compilertool,youwilldis-
cover the following messages:
Note: 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 )todiscover
the deprecated item and the code that refers to this item: warning: [deprecation] name in Employee
has been deprecated = "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.)
Forexample, Listing 3-40 uses @SuppressWarnings with a "deprecation"
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
Search WWH ::

Custom Search