import java.lang.annotation.*;
import java.lang.reflect.AnnotatedParameterizedType;
import java.lang.reflect.Method;
import java.util.*;
public class Main {
Method m
= Foo.
class.
getDeclaredMethod("bar",
List.
class);
var at = m.getAnnotatedParameterTypes()[0];
var ata = ((AnnotatedParameterizedType)at).getAnnotatedActualTypeArguments()[0];
// get all annotations
for(var a: ata.getAnnotations()) {
}
// or check the presence of a known annotation
System.
out.
println(ata.
getAnnotation(Important.
class) != null); }
class Foo {
void bar(List<@Important String> b) {}
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
@interface Important {}
aW1wb3J0IGphdmEubGFuZy5hbm5vdGF0aW9uLio7CmltcG9ydCBqYXZhLmxhbmcucmVmbGVjdC5Bbm5vdGF0ZWRQYXJhbWV0ZXJpemVkVHlwZTsKaW1wb3J0IGphdmEubGFuZy5yZWZsZWN0Lk1ldGhvZDsKaW1wb3J0IGphdmEudXRpbC4qOwoKcHVibGljIGNsYXNzIE1haW4gewogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgdGhyb3dzIE5vU3VjaE1ldGhvZEV4Y2VwdGlvbiB7CiAgICAgICAgTWV0aG9kIG0gPSBGb28uY2xhc3MuZ2V0RGVjbGFyZWRNZXRob2QoImJhciIsIExpc3QuY2xhc3MpOwoKICAgICAgICB2YXIgYXQgPSBtLmdldEFubm90YXRlZFBhcmFtZXRlclR5cGVzKClbMF07CiAgICAgICAgdmFyIGF0YSA9ICgoQW5ub3RhdGVkUGFyYW1ldGVyaXplZFR5cGUpYXQpLmdldEFubm90YXRlZEFjdHVhbFR5cGVBcmd1bWVudHMoKVswXTsKCiAgICAgICAgLy8gZ2V0IGFsbCBhbm5vdGF0aW9ucwogICAgICAgIGZvcih2YXIgYTogYXRhLmdldEFubm90YXRpb25zKCkpIHsKICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKGEpOwogICAgICAgIH0KCiAgICAgICAgLy8gb3IgY2hlY2sgdGhl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