Debian Codegraph @

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

raw
1 import org.checkerframework.checker.nullness.qual.*;
2
3 interface FunctionAC {
4 String apply(String s);
5 }
6
7 interface FunctionAC2 {
8 String apply(@Nullable String s);
9 }
10
11 class AssignmentContext {
12 // Test assign
13 FunctionAC f1 = String::toString;
14 // :: error: (methodref.receiver.invalid)
15 FunctionAC2 f2 = String::toString;
16
17 // Test casts
18 Object o1 = (Object) (FunctionAC) String::toString;
19 // :: error: (methodref.receiver.invalid)
20 Object o2 = (Object) (FunctionAC2) String::toString;
21
22 void take(FunctionAC f) {
23 // Test argument assingment
24 take(String::toString);
25 }
26
27 void take2(FunctionAC2 f) {
28 // Test argument assingment
29 // :: error: (methodref.receiver.invalid)
30 take2(String::toString);
31 }
32
33 FunctionAC supply() {
34 // Test return assingment
35 return String::toString;
36 }
37
38 FunctionAC2 supply2() {
39 // Test return assingment
40 // :: error: (methodref.receiver.invalid)
41 return String::toString;
42 }
43 }