Debian Codegraph @

checker/tests/nullness/java8/methodref/MemberReferences.java

raw
1 import org.checkerframework.checker.nullness.qual.*;
2
3 abstract class References {
4
5 void context(References c) {
6
7 // No error
8 FuncA funcA1 = References::aMethod1;
9 // No error, covariant parameters
10 FuncA funcA2 = References::aMethod2;
11 // :: error: (methodref.return.invalid)
12 FuncA funcA3 = References::aMethod3;
13 // :: error: (methodref.return.invalid)
14 FuncA funcA4 = References::aMethod4;
15
16 // :: error: (methodref.param.invalid)
17 FuncB funcB1 = References::aMethod1;
18 // No error
19 FuncB funcB2 = References::aMethod2;
20 // :: error: (methodref.return.invalid) :: error: (methodref.param.invalid)
21 FuncB funcB3 = References::aMethod3;
22 // :: error: (methodref.return.invalid)
23 FuncB funcB4 = References::aMethod4;
24
25 FuncA typeArg1 = References::<@NonNull String>aMethod5;
26 // :: error: (methodref.param.invalid)
27 FuncB typeArg2 = References::<@NonNull String>aMethod5;
28 }
29
30 abstract @NonNull String aMethod1(@NonNull String s);
31
32 abstract @NonNull String aMethod2(@Nullable String s);
33
34 abstract @Nullable String aMethod3(@NonNull String s);
35
36 abstract @Nullable String aMethod4(@Nullable String s);
37
38 abstract <T> T aMethod5(T t);
39
40 interface FuncA {
41 @NonNull String method(References a, @NonNull String b);
42 }
43
44 interface FuncB {
45 @NonNull String method(References a, @Nullable String b);
46 }
47 }