| 4 | // Visit http://OnJava8.com for more book information. |
| 5 | |
| 6 | final class IntegerSingleton |
| 7 | implements Resource<Integer> { |
| 8 | private static IntegerSingleton value = |
| 9 | new IntegerSingleton(); |
| 10 | private Integer i = Integer.valueOf(0); |
| 11 | private IntegerSingleton() { |
| 12 | System.out.println("IntegerSingleton()"); |
| 13 | } |
| 14 | public static IntegerSingleton instance() { |
| 15 | return value; |
| 16 | } |
| 17 | @Override public synchronized |
| 18 | Integer get() { return i; } |
| 19 | @Override public synchronized |
| 20 | void set(Integer x) { i = x; } |
| 21 | } |
| 22 | |
| 23 | public class SingletonPattern { |
| 24 | public static <T> void show(Resource<T> r) { |
nothing calls this directly
no outgoing calls
no test coverage detected