Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. class MyClass {
  2. static final MyClass _singleton = new MyClass._internal();
  3.  
  4. factory MyClass() {
  5. return _singleton;
  6. }
  7.  
  8. MyClass._internal() {
  9. ... // initialization logic here
  10. }
  11.  
  12. ... // rest of the class
  13. }
  14.  
  15. // consuming code
  16. MyClass myObj = new MyClass(); // get back the singleton
  17. ...
  18. // another piece of consuming code
  19. MyClass myObj = new MyClass(); // still getting back the singleton
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement