Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8340447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:10:59+00:00 2026-06-09T05:10:59+00:00

I read Effective Java and there it’s stated that a singleton is best implemented

  • 0

I read Effective Java and there it’s stated that a singleton is best implemented using enum.

This approach is functionally equivalent to the public field approach, except that it is more concise, provides the serialization machinery for free, and provides an ironclad guarantee against multiple instantiation, even in the face of sophisticated serialization or reflection attacks. While this approach has yet to be widely adopted, a single-element enum type is the best way to implement a singleton.

Still, this seems like a trade-off to achieve on the fly serialization and true single instance, but you lose the more friendly OOP approach of a classical singleton. Enums can’t be inherited, can implement only an interface and if you want to provide a skeleton class you need to create a helper class.

So, why should we accept enum as the best implementation for a singleton, other than the reasons stated above?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:11:00+00:00Added an answer on June 9, 2026 at 5:11 am

    this seems like a trade-off to achieve on the fly serialization

    For me it’s a lot simpler and more concise to write something like

    enum Singleton {
        INSTANCE;
    }
    

    If you have a need to write a lot more code or introduce complexity then do so, but this is rarely required IMHO.

    you lose the more friendly OOP approach of a classical singleton.

    I find using fields to be simpler.

    Enums can’t be inherited,

    True, but having multiple singletons is suspect in itself. Enums can inherit from interfaces which allows you to swap one implementation for another.

    If you want to provide a skeleton class you need to create a helper class

    A helper class doesn’t have any state. A skeleton class might have some state in which case you need delegation.

    BTW: You can use enum for helper classes

    enum Helper {;
        public static my_static_methods_here;
    }
    

    why should we accept enum as the best implementation for a singleton

    I would follow the YAGNI principle. Only develop what you need, not what you imagine you might need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It was suggested that Effective Java is a great book to read before programming
I read from Effective Java that In the absence of synchronization the following sequence
I read Effective Java, and there written If a class cannot be made immutable,
I read Effective Java by Joshua Bloch and removed the 'Constant Interface anti-pattern' from
I'm using some functionality in Java that I don't really understand so I want
I'm trying out Effective Java book and enjoying it. I read Builder pattern and
I read about this from Effective c++ ,this is Col.10. It say it's a
Are there (performance) penalties* associated with the Enum Singleton Pattern in any way, as
I posting a doubt that I came across reading Effective Java. I apologize if
I've read in a technical paper that using XSLT for making amendments in an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.