Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyClass {
- static final MyClass _singleton = new MyClass._internal();
- factory MyClass() {
- return _singleton;
- }
- MyClass._internal() {
- ... // initialization logic here
- }
- ... // rest of the class
- }
- // consuming code
- MyClass myObj = new MyClass(); // get back the singleton
- ...
- // another piece of consuming code
- MyClass myObj = new MyClass(); // still getting back the singleton
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement