MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / SingletonPattern

Class SingletonPattern

patterns/SingletonPattern.java:23–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23public 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:
43Inside main()
44IntegerSingleton()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected