forked from sermakov/JavaPatternMirea
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsk8.java
More file actions
56 lines (43 loc) · 1.42 KB
/
tsk8.java
File metadata and controls
56 lines (43 loc) · 1.42 KB
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
52
53
54
55
56
package some;
import java.util.ArrayList;
public class tsk8 {
static void prt(Object a) { System.out.println(a); }
@SuppressWarnings("StatementWithEmptyBody")
public static void main(String[] args) throws Exception {
var a = new Obvl() { @Override void nf() {
prt("notifying...");
super.nf();
} };
for (var i = 0; i < 5; i++,
a.dd(() -> prt("update")) );
a.nf();
new Ctx(1);
new Ctx(2);
}
////////////////////////////////////////
interface Obsr { void up(); }
static abstract class Obvl {
private final ArrayList<Obsr> _a = new ArrayList<>();
void nf() { _a.forEach(Obsr::up); }
final void dd(Obsr a) { _a.add(a); }
}
////////////////////////////////////////
static abstract class St {
abstract int a();
@Override public String toString() { return "" + a(); }
}
@SuppressWarnings("unused")
static class St1 extends St { @Override public int a() { return 1; } }
@SuppressWarnings("unused")
static class St2 extends St { @Override public int a() { return 2; } }
static class Ctx {
Ctx(int a) throws Exception
{ prt(Class
.forName(
tsk8.class.getCanonicalName() +
'$' +
St.class.getSimpleName() + a)
.getDeclaredConstructors()[0]
.newInstance()); }
}
}