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 864729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:31:35+00:00 2026-05-15T09:31:35+00:00

Item 3 of Josh Block’s Effective Java (Enforce the Singleton Property With a Private

  • 0

Item 3 of Josh Block’s Effective Java (Enforce the Singleton Property With a Private Constructor or an Enumerator) mentions that “While this approach has yet to be widely adopted, a single-element enum type is the best way to implement a singleton.”

Example:

   public enum Elvis {
       INSTANCE;
       private final String[] favoriteSongs =
           { "Hound Dog", "Heartbreak Hotel" };
       public void printFavorites() {
           System.out.println(Arrays.toString(favoriteSongs));
       }
   }

Continued: “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.”

The biggest negative I see is: aren’t enums not supposed to have mutable state? It seems common to use a Singleton with state.

So has this pattern actually become more common since the publication date (2nd Edition published 2008)?

  • 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-15T09:31:36+00:00Added an answer on May 15, 2026 at 9:31 am

    While enums aren’t generally given mutable state, this fact is based on assumptions of how an enum is going to be used. While these assumptions usually hold, they don’t always, and one such case where they do not is in the creation of a Singleton.

    While it’s not the most common use of enums, it’s perfectly legitimate to have an enum with a mutable state, though you may want to indicate this fact in your code so any other programmer who might be looking at it don’t get confused.

    As for a popularity of this design pattern, I’ve seen it fairly often, but not so much that I’d say it has become “common.”

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

Sidebar

Related Questions

I've been reading Josh Bloch's 'Effective Java 2nd Edition'. Item 43 states 'Return empty
In Josh Bloch's excellent book Effective Java under Item 39 he says: [D]efensive copies
Consider the following from Effective Java Item 11 (Override clone judiciously) where Josh Bloch
Item 16 of Effective Java 2nd edition, favor composition over inheritance says the following
In Effective Java inside the item Item 22: Favor static member classes over nonstatic
I have an Item class. There's an itemType field inside of that class which
Item in the recordset rstImportData(Flat Size) is = Null With that, given the following
I have a TreeView that the user navigates to select an item for display
List item I use following Regex to validate a string ^[a-zA-Z0-9-/]* private static void
Accordion item Visibility property can be bound like this: <layoutToolkit:Accordion x:Name=MyAccordion> <layoutToolkit:AccordionItem Visibility={Binding IsVisible,

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.