Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2014
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. class Foo {
  2.     private static Foo _instance;
  3.  
  4.     public static void initializeInstance(Context context) { // This is thread safe in real-world
  5.         // runs heavy stuff
  6.     }
  7.  
  8.     public static Foo getInstance(Context context) {
  9.         if (_instance == null) {
  10.             throw new IllegalStateException("not initialized");
  11.         }
  12.         return _instance;
  13.     }
  14. }
  15.  
  16. // Usage:
  17. class App {
  18.     public void entryPoint() {
  19.         Foo.inititalizeInstance(context); // in real world this runs async
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement