| 1 |
import org.checkerframework.checker.nullness.qual.*; |
| 2 |
|
| 3 |
public class OptionsTest { |
| 4 |
|
| 5 |
class MyAnnotation {} |
| 6 |
|
| 7 |
// Annotated identically to java.lang.reflect.Field.getAnnotation |
| 8 |
public static <T1 extends @Nullable MyAnnotation> @Nullable T1 getAnnotation( |
| 9 |
Class<@NonNull T1> obj) { |
| 10 |
return null; |
| 11 |
} |
| 12 |
|
| 13 |
public static @Nullable MyAnnotation safeGetAnnotationNonGeneric( |
| 14 |
Class<@NonNull MyAnnotation> annotationClass) { |
| 15 |
@Nullable MyAnnotation cast = getAnnotation(annotationClass); |
| 16 |
@Nullable MyAnnotation annotation = cast; |
| 17 |
return annotation; |
| 18 |
} |
| 19 |
|
| 20 |
public static <T2 extends MyAnnotation> @Nullable T2 safeGetAnnotationGeneric( |
| 21 |
Class<@NonNull T2> annotationClass) { |
| 22 |
@Nullable T2 cast = getAnnotation(annotationClass); |
| 23 |
@Nullable T2 annotation = cast; |
| 24 |
return annotation; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
/* Local Variables: */ |
| 29 |
/* compile-command: "javac -processor org.checkerframework.checker.nullness.NullnessChecker -Xbootclasspath/p:$CHECKERFRAMEWORK/checker/dist/jdk8.jar OptionsTest.java" */ |
| 30 |
/* compile-history: ("javac -processor org.checkerframework.checker.nullness.NullnessChecker -Xbootclasspath/p:$CHECKERFRAMEWORK/checker/dist/jdk8.jar OptionsTest.java") */ |
| 31 |
/* End: */ |