Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo {
- private static Foo _instance;
- public static void initializeInstance(Context context) { // This is thread safe in real-world
- // runs heavy stuff
- }
- public static Foo getInstance(Context context) {
- if (_instance == null) {
- throw new IllegalStateException("not initialized");
- }
- return _instance;
- }
- }
- // Usage:
- class App {
- public void entryPoint() {
- Foo.inititalizeInstance(context); // in real world this runs async
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement