1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
import java.lang.annotation.Annotation;
import java.lang.reflect.*;
import org.checkerframework.checker.regex.qual.Regex;
class AnnotatedTypeParams3 {
private <T extends Annotation> T safeGetAnnotation(Field f, Class<T> annotationClass) {
T annotation;
try {
annotation = f.getAnnotation((Class<T>) annotationClass);
} catch (Exception e) {
annotation = null;
}
return annotation;
}
private <T extends Annotation> T safeGetAnnotation2(Field f, Class<T> annotationClass) {
T annotation;
try {
annotation = f.getAnnotation(annotationClass);
} catch (Exception e) {
annotation = null;
}
return annotation;
}
<@Regex T extends @Regex Object> void test(T p) {
Object o = p;
@Regex Object re = o;
}
<T extends @Regex Object> void test2(T p) {
Object o = p;
@Regex Object re = o;
}
// TODO: do we want to infer the type variable annotation on local variable "o"?
<T> void test3(@Regex T p) {
T o = p;
@Regex T re = o;
}
}
class OuterClass<E> {
public InnerClass<E> method() {
return new InnerClass<>();
}
class InnerClass<A extends E> {}
}
|