Debian Codegraph @

checker/tests/nullness/generics/GenericArgs2.java

raw
1 import java.io.*;
2 import java.util.HashMap;
3 import java.util.Map;
4 import org.checkerframework.checker.nullness.qual.*;
5
6 class Cell<T extends @Nullable Object> {
7 void add(T arg) {}
8 }
9
10 class GenericArgs2 {
11 static <F extends Object> void test1(Cell<F> collection) {
12 // :: error: (argument.type.incompatible)
13 collection.add(null); // should fail
14 }
15
16 static <F extends @Nullable Object> void test2(Cell<F> collection) {
17 // :: error: (argument.type.incompatible)
18 collection.add(null); // should fail
19 }
20
21 static void test3(Cell<@Nullable Object> collection) {
22 collection.add(null); // valid
23 }
24 // No "<F super Object>" version of the above, as that is illegal in Java.
25
26 static class InvariantFilter {}
27
28 static class Invariant {}
29
30 HashMap<Class<? extends InvariantFilter>, Map<Class<? extends Invariant>, Integer>> filter_map1;
31 MyMap<@Nullable Class<? extends InvariantFilter>, Map<Class<? extends Invariant>, Integer>>
32 filter_map2;
33
34 public GenericArgs2(
35 HashMap<Class<? extends InvariantFilter>, Map<Class<? extends Invariant>, Integer>>
36 filter_map1,
37 MyMap<
38 @Nullable Class<? extends InvariantFilter>,
39 Map<Class<? extends Invariant>, Integer>>
40 filter_map2) {
41 this.filter_map1 = filter_map1;
42 this.filter_map2 = filter_map2;
43 }
44
45 class MyMap<K extends @Nullable Object, V extends @Nullable Object> {}
46 }