| 21 | } |
| 22 | |
| 23 | public class SingletonPattern { |
| 24 | public static <T> void show(Resource<T> r) { |
| 25 | T val = r.get(); |
| 26 | System.out.println(val); |
| 27 | } |
| 28 | public static <T> void put(Resource<T> r, T val) { |
| 29 | r.set(val); |
| 30 | } |
| 31 | public static void main(String[] args) { |
| 32 | System.out.println("Inside main()"); |
| 33 | Resource<Integer> ir = |
| 34 | IntegerSingleton.instance(); |
| 35 | Resource<Integer> ir2 = |
| 36 | IntegerSingleton.instance(); |
| 37 | show(ir); |
| 38 | put(ir2, Integer.valueOf(9)); |
| 39 | show(ir); |
| 40 | } |
| 41 | } |
| 42 | /* Output: |
| 43 | Inside main() |
| 44 | IntegerSingleton() |
nothing calls this directly
no outgoing calls
no test coverage detected