When it comes to jdk, it is relatively common for everyone. In interfaces and classes, we will also use it together. There are different types of annotations in jdk. This article will explain the methods and examples of three common annotations.
1. @Override : used for methods, indicating that the method overrides the parent class method, such as toString().
//#2.1 JDK5.0 Override the parent class method class Parent1_2{ public void init(){ } } class Son1_2 extends Parent1_2{ @Override public void init() { } } //#2.2 JDK6.0 implements the parent interface method interface Parent1_3{ public void init(); } class Son1_3 implements Parent1_3{ @Override public void init() { } }
2. @Deprecated: Indicates that the method has expired and is not recommended for developers to use.
//#1 method expires class Parent1_1{ @Deprecated public void init(){ } }
3. @FunctionalInterface: used to agree on functional interfaces.
Functional interface: If there is only one abstract method in the interface (which can contain multiple default methods or multiple static methods), the interface is called a functional interface.
@FunctionalInterface public interface AD { public void adAttack(); }
The above is an introduction to JDK annotations in Java. If you are interested in these annotation types, you can continue to study in depth after class. Of course, jdk annotation types are relatively rich, and we will continue to update them in the future.