Static inner class over Singleton
Hi,
Whether we can implement singleton using static inner class? What is the advantage of doing so and what are the pros and cons of it?
Because Static inner class have restriction as below:-
1. A singleton class can extends class and implement interfaces , while Static class can not.
2. A singleton can be instantiated lazily or asynchronously while a static class is generally initialized when it is first loaded.
3.A singleton class can extended and its methods can be overridden.
4. The most important advantage is the singleton can be handled polymorphic ally without forcing their users to assume that there is only one instance.
Hence why need to go for a Static inner class over singleton?