Update Java_反射与注解.md
This commit is contained in:
parent
4ab3c93467
commit
9a86a4c5f6
@ -74,7 +74,7 @@ public Constructor<T> getConstructor(Class<?>... parameterTypes)
|
|||||||
public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
|
public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
|
||||||
```
|
```
|
||||||
|
|
||||||
获取指定的构造器后,可以使用 `newInstance` 方法来创建其实例,实例如下:
|
获取指定的构造器后,可以使用 `newInstance` 方法来创建其实例,示例如下:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
class Test {
|
class Test {
|
||||||
@ -287,8 +287,11 @@ public @interface Override {
|
|||||||
```java
|
```java
|
||||||
// 获取所有注解
|
// 获取所有注解
|
||||||
public Annotation[] getAnnotations()
|
public Annotation[] getAnnotations()
|
||||||
|
// 获取本元素上直接声明的所有注解,忽略inherited来的
|
||||||
public Annotation[] getDeclaredAnnotations()
|
public Annotation[] getDeclaredAnnotations()
|
||||||
|
// 获取指定类型的注解,如果不存在则返回null
|
||||||
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
|
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
|
||||||
|
// 判断是否有指定类型的注解
|
||||||
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
|
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -310,7 +313,8 @@ class Test {
|
|||||||
/*当只有一个值并且其对应的方法名为value时候,可以省略value = */
|
/*当只有一个值并且其对应的方法名为value时候,可以省略value = */
|
||||||
@Json("姓名")
|
@Json("姓名")
|
||||||
private String name;
|
private String name;
|
||||||
@Json(value = "出生日期", format = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
|
@Json(value = "出生日期", format = "yyyy-MM-dd HH:mm:ss")
|
||||||
private Date birthday;
|
private Date birthday;
|
||||||
......
|
......
|
||||||
}
|
}
|
||||||
@ -379,4 +383,4 @@ class Test {
|
|||||||
|
|
||||||
## 参考资料
|
## 参考资料
|
||||||
|
|
||||||
+ 马俊昌 . Java编程的逻辑 . 机械工业出版社 . 2018-01-01
|
+ 马俊昌 . Java编程的逻辑 . 机械工业出版社 . 2018-01-01
|
||||||
|
Loading…
x
Reference in New Issue
Block a user