FasterXML / FasterXML/java-classmate

AnnotatedType support

未關閉
#25 7 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Java
星號
266
分支
47
平均合併
1 小時 42 分鐘
30 天內合併 PR
1

描述

New to Java 8, the AnnotatedType class carries annotations bind to types in Generic expressions.
So if I write

```
@MaxLength(3) List<@NotNull Integer> myField;
```

I can get the `@NotNull` annotation via something like:

```
Field f = MyClass.class.getDeclaredField("myField");
AnnotatedParameterizedType annType = (AnnotatedParameterizedType) field.getAnnotatedType();
AnnotatedType[] childAnnotatedTypes = annType.getAnnotatedActualTypeArguments();
```

But then I have to assume the parameter I want is the first in the returned array. But maybe I have something like

```
class MyFunnyList implements List<@NotNull Integer> {}
// ...
private MyFunnyList<@Null String> myFunnyField;
```

Using `ResolvedType`, I can call `type.typeParametersFor(List.class).get(0)` to get the correct parameter type (`Integer` rather than `String`). It'd be nice to have also a way to retrieve the annotations associated with it (`@NotNull` rather than `@Null`). Note that this feature must not break support for Java 7, so some type of switch will probably need to be used.

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。