forked from sermakov/JavaPatternMirea
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsk5.java
More file actions
39 lines (32 loc) · 954 Bytes
/
tsk5.java
File metadata and controls
39 lines (32 loc) · 954 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
package some;
public class tsk5 {
static void prt(Object a) { System.out.println(a); }
public static void main(String[] args) {
//noinspection ConstantConditions
prt(A.a == null);
prt(B.gb() == null);
prt(C.gc() == null);
}
@SuppressWarnings("InstantiationOfUtilityClass")
static class A {
static final A a = new A();
private A() {}
}
static class B {
private static B b = null;
private B() { b = this; }
static B gb() { return b; }
}
static {
try {
final var b = B.class.getDeclaredFields()[0];
b.setAccessible(true);
b.set(null, B.class.getDeclaredConstructors()[0].newInstance());
} catch (Exception a) { a.printStackTrace(); }
}
static class C {
private static C c = null;
private C() {}
static C gc() { return c == null ? c = new C() : c; }
}
}