Annotations)
Annotation is a modifier that can be added to the code. It can be used for package declaration, type declaration, constructors, methods, fields, parameters, and variables. Tiger includes built-in comments and supports custom comments compiled by you.
It has three built-in Annotations: suppresswarnings, deprecated, and override.
Suppresswarnings
This annotation prevents warnings thrown by the compiler at the class and method levels. Sometimes you know that it is better to use some methods that are not recommended, or you must execute some static methods that have type security. If you use these methods, you will continuously receive warnings about irrelevant things. Suppresswarnings can help the compiler not bother you!
SupresswarningsYesWith a variable-so you use a single annotation type with the variable. A value array can be used to provide variables. Each value indicates a specific warning type to block.
@ Suppresswarnings ("deprecation") // use the unrecommended public static void selfdestruct () {thread. currentthread (). Stop ();}
@ Suppresswarings ("unchecked") Public void nongenericsmethod () {list wordlist = new arraylist (); // The wordlist type of the value in the list is not specified. add ("foo"); // exceptions may be thrown}
The values of variables in suppresswarnings use arrays, allowing you to block multiple warnings in the same comment. For example,
@SuppressWarnings("unchecked", "fallthrough")Use an array of two values. This function is for processing
Errors provide a very flexible approach without a lot of work.
Deprecated
Deprecated is not very useful. UseDeprecatedTo comment out methods that should not be used. Majority
In this case, @ deprecated and javadoc are both used.
Public class deprecatedclass {@ deprecated public void dosomething () {// code
}
// Replace dosomething () with the public void dosomethingelse () {// code }}
If the declared method is replaced or called, the compiler processes the annotation and finds that
Method, and send an error message.
Override
Override should be used only for methods (not for classes, package declarations, or other constructor ). It indicates that the annotation method will overwrite
Class.
@Overridepublic int hashCode() { ...}
If you write hashcode () as hashcode () "C", there will be no errors during compilation, and only errors will be reported during runtime.
By using override annotations, if you do not actually execute the reload compilation, an error is reported. Modify override comment in the parent class Method
Changes also take effect. For example, if the parent class method adds a parameter or the method is renamed, an error occurs during subclass compilation.
It will not be confusing.