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

  • SEARCH
  • Home
  • 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 4242646
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:28:14+00:00 2026-05-21T03:28:14+00:00

I got used to writing enum-style singleton when all of a sudden, someone reviewing

  • 0

I got used to writing enum-style singleton when all of a sudden, someone reviewing my code asked me change it because it is not in the project’s coding convention. He asked me what is the benefit, I just said it is easier to write.

I just want to know if there’s really no benefit in using it. I understand that enum for java might not have been implemented for this purpose but even then, is it wrong to use it this way?

  • 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-05-21T03:28:15+00:00Added an answer on May 21, 2026 at 3:28 am

    I got used to writing enum-style singleton when all of a sudden, someone reviewing my code asked me change it because it is not in the project’s coding convention. He asked me what is the benefit, I just said it is easier to write.

    Another benefit of enums-style singletons over classic ones is that they have singleton semantics in the face of Java Object Serialization. (The Java Object Serialization and the enum base-class combine to ensure that deserialization doesn’t create copies of enum constants. It is rather hard to get this right for a singleton implemented the classic way. And if you get it wrong there can be multiple instances of some singleton class … and potentially problems.)

    But I’d be inclined to carefully examine the basis for your colleague’s objection.

    • Does the coding style specifically forbid enum’s ?
    • Does the coding style specifically forbid enum-style singletons ?
    • Does the coding style specifically prescribe a particular way of implementing singletons ?

    If none of the above, then “not in the coding standard” doesn’t sound like a valid objection. (Surely, something doesn’t need to be explicitly “in” the coding standard to be allowed … that would be control-freak crazy stuff!)

    My guess is that your colleague has spotted an example of a singleton in your coding standard, and concluded (incorrectly) that it means that singletons must be implemented that way.

    (Or maybe you really are lumbered with an overly prescriptive coding standard. If that’s the case, you have my sympathy.)


    The other point is that the Singleton pattern needs to be used sparingly, as it is an impediment to testability, and potentially problematic for applications that are deployed in web containers and the like.

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

Sidebar

Related Questions

When i test my code via Analyzer then got: Instance variable used while 'self'
After going through Marshall code snippet Got the Idea that marshalling is used to
After a lot of writing in Q10 on Windows , I got used to
I am writing a large amount of code and I haven't got enough experience
Having used Cucumber about a year ago, I got used to writing scenarios this
I have got to know that src/test/java is used for writing unit tests. I
I'm writing an MPI program for a parallel computing class. I've got the code
What I've got are chunks of code that are used over and over again
I got used so much to this in notepad++ that when i switched to
During my experience as a software developer I got used to a practice of

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.