Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Static inner class over Singleton

User_19BPUJul 2 2012 — edited Jul 3 2012
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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 31 2012
Added on Jul 2 2012
6 comments
1,761 views