I am looking at a rather trivial class with a single method that defines an annotated receiver type:
class Foo<T> {
void foo(Foo<@Bar T> this) {}
}
I would now like to access the type annotation on the receiver type's parameter @Bar
but the Java reflection API returns an annotated raw type when accessing the receiver:
assert Foo.class.getDeclaredMethod("foo")
.getAnnotatedReceiverType()
instanceof AnnotatedParameterizedType;
The assertion fails as the annotated type that is returned is returned as a raw type Foo
. Is this intentional? I can still find the @Bar
annotation when accessing private properties of the implementation of AnnotatedType
that is returned.
I am running a recent version of Java 8.