FasterXML / FasterXML/java-classmate

AnnotatedType support

オープン
#25 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Java
スター
266
フォーク
47
平均マージ
1時間 42分
マージ済み PR(30日)
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 を短くまとめたダイジェスト。