Skip to content

Commit

Permalink
新增JAVA注解-基础
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcaffebabe committed Nov 15, 2019
1 parent 46f3d54 commit e6f8159
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions 后端开发/语言/JAVA/高级/注解.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@
- ②代码分析:通过代码里标识的注解对代码进行分析【使用反射】
- ③编译检查:通过代码里标识的注解让编译器能够实现基本的编译检查【Override】

# JAVA提供的基本注解

- **@Override**
- 限定重写父类方法。对于子类中被@Override 修饰的方法,如果存在对应的被重写的父类方法,则正确;如果不存在,则报错。@Override 只能作用于方法,不能作用于其他程序元素
- **@Deprecated**
- 用于表示某个程序元素(类、方法等)已过时。如果使用了被@Deprecated修饰的类或方法等,编译器会发出警告
- **@SuppressWarnings**
- 抑制编译器警告
- **@SafeVarargs**
- 是JDK 7 专门为抑制“堆污染”警告提供的
- **@FunctionalIterface**
- @FunctionalInterface就是用来指定某个接口必须是函数式接口,否则就会编译出错


# 自定义注解

```java
元注解
public @interface 注解名称{
属性列表;
}
public @interface 注解名称{
属性列表;
}
```

属性的返回值类型有下列取值:
Expand Down

0 comments on commit e6f8159

Please sign in to comment.