Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science mluckner@mini.pw.edu.pl http://www.mini.pw.edu.pl/~lucknerm
} Annotations do not directly affect program semantics. } May be recognized by tools and libraries which could change behavior. } Annotations may be read from source files, class files or by reflection at run time. 2
} @Override a method is intended to override a method in a superclass. } @Deprecated a class or a method may be indicated as not to be used any more (generates compiler warning if used). } @SupressWarnings turns of certain warnings from a compiler deprecation, unchecked, fallthrough, path, serial,finally, all @SupressWarnings(''deprecation'',''serial'') 3
} Annotations with many parameters must be called with parameters names } A single parameter named value may be shortened in use. 4
} Annotations are created with specialized syntax similar to interfaces. } Each method declaration defines an element of the annotation type. } Method declaration must not have any parameters or a throws clause. } Return types are restricted to primitives, String, Class, enums and arrays of preceding types. } Methods can have defaults values. 5
6
} @Retention whether the annotations are available SOURCE, CLASS, RUNTIME } @Target defines where you can apply this annotation METHOD, PARAMETER, CONSTRUCTOR, LOCAL VARIABLE, ANNOTATION TYPE, PACKAGE 7
8
/* This is a comment * that continues * across lines */ /* This is a comment that continues across lines */ // This is a one-line comment 9
/** A class comment */ public class Documentation1 { /** A field comment */ public int i; /** A method comment */ public void f() {} } 10
/** * You can <em>even</em> insert a list: * <ol> * <li> Item one * <li> Item two * <li> Item three * </ol> */ 11
} @see This tag allows you to refer to the documentation in other classes. @see classname @see fully-qualified-classname @see fully-qualified-classname#method-name } {@link package.class#member label} can be used inline as the hyperlink text } {@docroot} the relative path to the documentation root directory } {@inheritdoc} Inherits the documentation from the nearest base class 12
} @version @version version-information } @author @author author-information } @since indicate the version of this code that began using a particular feature. 13
} @param @param parameter-name description parameter-name the identifier in the method parameter list, description text that can continue on subsequent lines } @return @return description description gives you the meaning of the return value. 14
} @throws @throws fully-qualified-class-name description fully-qualified-class-name gives an unambiguous name of an exception class description tells you why this particular type of exception can emerge from the method call. } @deprecated indicate features that were superseded by an improved feature 15
/** The first Thinking in Java example program. * Displays a string and today s date. * @author Bruce Eckel * @author www.mindview.net * @version 4.0 */ public class HelloDate { /** Entry point to class & application. * @param args array of string arguments * @throws exceptions No exceptions thrown */ public static void main(string[] args) { System.out.println("Hello, it s: "); System.out.println(new Date()); } } /* Output: (55% match) Hello, it s: Wed Oct 05 14:39:36 MDT 2005 */ 16