184 CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES
CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES 185 Then, compiling with the specified -Xlint option shows the details: > javac -Xlint:deprecation Dep.java Dep.java:11: warning: [deprecation] myDeprecatedMethod() in Dep has been deprecated Dep.myDeprecatedMethod(); ^ 1 warning Nothing new here. This is the JDK 5.0 @Deprecate annotation just another way of doing what @deprecated does. The @SuppressWarnings Annotation There are two types of annotations: those that accept arguments and those that don t. The @Deprecated annotation is an example of one that doesn t. The @SuppressWarnings annotation is one that does. With the @Deprecated annotation, a method or class is either deprecated or it isn t. Adding the metadata is an on/off flag. On the other hand, the @SuppressWarnings annotation says you would like to either suppress a specific type of warning or not. The types will be specific to the compiler vendor. For Sun s compiler, there are two warnings that can be suppressed: deprecation and unchecked. An unchecked value has to do with compile-time checks for generics. If you don t want to update legacy code to avoid warnings related to generics, you can add an @SuppressWarnings annotation to your source: @SuppressWarnings({”unchecked”}) Note You can add the suppression at the class or method level. If at the class level, all warnings of unchecked usages in the class will be suppressed. The argument to the annotation is an array of strings hence the extra set of {}s in there. If instead of suppressing warnings related to generics you want to avoid the warning generated by compiling the source in Listing 10-1, you would add an @SuppressWarnings({”deprecation”}) annotation to where the deprecated method call was made. Listing 10-2 shows an updated DeprecatedUsage class.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services