184 CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES
186 CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES Listing 10-2. @SuppressWarnings Annotation Usage class DeprecatedUsage { @SuppressWarnings(”deprecation”) public void useDeprecatedMethod() { Dep.myDeprecatedMethod(); } } After adding the annotation, the compiler won t complain anymore. The @Override Annotation The third JDK 5.0 annotation is @Override. Use of this annotation tells the compiler that the method is supposed to be overriding a method in the superclass. The compiler will warn you if it doesn t. This will catch common mistakes, such as a method with the wrong case for example, hashcode() versus hashCode(). In such a case, a quick scan through the code may look right, and the compiler won t complain at compilation time. Only after your resultant program produces odd results when hashCode() should be called does the problem of the incorrect case in your method reveal itself. Well, it doesn t exactly reveal itself, but you know something is wrong, and you have to hunt down the problem. By using the annotation, errors of this nature will be caught much sooner in the development process. Listing 10-3 shows a program with a poorly overridden method. Listing 10-3. @Override Annotation Usage public class Over { public void overrideMe() { } } class SubOver extends Over { @Override public void overrideme() { } } Notice the poorly capitalized method without camelcase for the m in me. Had the source code not included the @Override annotation, the compiler would not have complained, producing a SubOver class with an overrideme() method. Any call to the overrideMe() method of SubOver would then result in the version in the parent class being called instead.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services