Home > Java > javaTutorial > body text

How to use java's JDK annotations

王林
Release: 2023-04-28 17:01:07
forward
1155 people have browsed it

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() {
}
}
Copy after login

2. @Deprecated: Indicates that the method has expired and is not recommended for developers to use.

//#1 方法过期
class Parent1_1{
@Deprecated
public void init(){
    }
}
Copy after login

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();
}
Copy after login

The above is the detailed content of How to use java's JDK annotations. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template