-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathA.java
More file actions
51 lines (42 loc) · 726 Bytes
/
A.java
File metadata and controls
51 lines (42 loc) · 726 Bytes
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
50
51
public class A {
int foo;
int getFoo() {
return this.foo;
}
void setFoo(int x) {
this.foo = x;
}
static A withFoo(int x) {
A a = new A();
a.foo = x;
return a;
}
static void run() {
A a = new A();
a.setFoo(1);
int x = a.getFoo();
A a2 = withFoo(2);
x = a.aGetter();
x = a2.notAGetter();
}
static class C1 {
A maybeId(A a) {
return a;
}
}
static class C2 extends C1 {
@Override
A maybeId(A a) {
return new A();
}
}
static A maybeIdWrap(A a, C1 c) {
return c.maybeId(a);
}
int aGetter() {
return maybeIdWrap(this, new C1()).foo;
}
int notAGetter() {
return maybeIdWrap(this, new C2()).foo;
}
}