Annotation Introduction
Annotation is a new technology development jdk1.5 structure provided, can effectively reduce the program configuration code may be structured definition, is a program implemented in the form of annotation development.
The notes explain just basic Java annotations:@Override、@Deprecated、@SuppressWarning
Accurate override (@Override)
When a subclass inherits the parent when the parent class method shortage of certain features if you find often adopt overwritten.
Two points clear:
If the subdivision development process forget extends the parent class, not override the call;
If overwritten when the word wrong, wrong compilation process does not appear, nor is overwritten.
Examples: one kind of observation overwritten additional annotations
class Zhujie{
public void connect(){
System.out.println("l允许所有设备连接");
}
}
class Data extends Zhujie{
@Override
public void connect(){
System.out.println("只允许以允许设备连接");
}
}
public class App2 {
public static void main(String[] args){
// new Data().connect();
Data a=new Data();
a.connect();
}
}
@ Override // clear that the method is a method to overwrite, overwrite if no compiler error.
Expired statement (@Deprecated)
Refers to a process of iterative software development project, there may be a method or class, due to defects in the initial design process, resulting in inappropriate places new version, this time for a transition to time, so the statement on the use of expired the purpose is to tell new users of these operations not be used again. Such an approach must utilize @Deprecated comment.
class Zhujie{
@Deprecated //旧系统继续使用,新系统不使用
public void connect(){
System.out.println("1122334455");
}
public void connection(){
}
}
public class App2 {
public static void main(String[] args){
new Zhujie().connect();
}
}
Output:
F: \ learning the Java \ java> javac App2.java
Note: App2.java use or covered obsolete API.
Note: For more information, please use the -Xlint: deprecation recompiled.
F: \ Java learning \ the Java> the Java App2
1,122,334,455
Suppress warnings (@SuppressWarning)
Eliminate message, error message repression.
class Zhujie{
@Deprecated //旧系统继续使用,新系统不使用
public void connect(){
System.out.println("**********");
}
public void connection(){
}
}
public class App2 {
@SuppressWarnings({"deprecation"})
public static void main(String[] args){
new Zhujie().connect();
}
}
Output: **********
following two sentences expired stated error will not occur again.
* Note: App2.java use or covered obsolete API.
* Note: For more information, please use the -Xlint: deprecation recompiled.