- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
public static void main(String[] args) {
testIndiaLazy();
}
private static void testIndiaLazy() {
LazyInstantiator lazyInstantiator = new LazyInstantiator();
lazyInstantiator.getInstance();
lazyInstantiator.getInstance();
}
public static class LazyInstantiator {
private Object instance;
public Object getInstance() {
System.out.println("getInstance");
if (instance != null || create());
return instance;
}
private boolean create() {
System.out.println("create");
instance = new Object();
return true;
}
}