JAVA
java
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
public class Program
{
public static void main(String[] args) {
FasterSingleton firstRef = FasterSingleton.get();
FasterSingleton secondRef = FasterSingleton.get();
System.out.println(firstRef == secondRef);
}
public static class Singleton {
private Singleton()
{
}
private static Singleton _inst;
synchronized public static Singleton get () {
if (_inst == null) {
_inst = new Singleton();
}
return _inst;
}
}
public static class FasterSingleton {
private FasterSingleton()
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run