Home  >  Article  >  Java  >  Methods and examples of using JDK annotations in Java

Methods and examples of using JDK annotations in Java

WBOY
WBOYforward
2023-04-23 10:46:141319browse

1. @Override: used for methods, indicating that the method overrides the parent class method, such as toString().

//#2.1 JDK5.0 复写父类方法
class Parent1_2{
public void init(){
}
}
class Son1_2 extends Parent1_2{
@Override
public void init() {
}
}
 
//#2.2 JDK6.0 实现父接口方法
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 方法过期
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 the detailed content of Methods and examples of using JDK annotations in Java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete