This class provides singleton class implementation which provides single instance of class.
Features of this class :-
- Single instance class
- Globally accessible object reference
- Thread safe
- Reflection safe
Requirements :-
- Private constructor.
- A static reference of its class.
- Single entry point static method.
- Thread safety measurement.
- Reflection safety measurements.
Note: I have purposely shown singleton example in java language, because in kotlin creating a singleton class is very easy.
object SingletonDemo.
Thats it!! Yes object keyword provides singleton implementation.