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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:47:32+00:00 2026-06-15T21:47:32+00:00

This seems like it would be a common question, but none of the items

  • 0

This seems like it would be a common question, but none of the items in the suggestion box exactly explained what I am wondering. In this link, everyone suggested using the enum type (which I’ve now researched, but never used prior). I was about to suggest simply using a HashMap and read the answers to see if the Enum ( http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html ) was ,in fact, a better answer. According to that link on oracle, “You should use enum types any time you need to represent a fixed set of constants.” So, it is.

My question is… why? Is it more of forming a contract that they will not change? Is it a shorter way of getting some class functionality? How’s the performance? Why is this any different than just defining the constants in the same class?

Thank you!

  • 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-15T21:47:33+00:00Added an answer on June 15, 2026 at 9:47 pm

    Enum instances are objects, encapsulating data and behaviour just like any other object. By passing enum instances around, anyone can call its methods. If you pass Map keys as Strings, for example, you can’t do anything useful with the key. Moreover, the code is less type-safe, and less self-documenting, since the String could very well be something completely different from what it’s supposed to be.

    What’s the most readable?

    public int countDays(Set<Month> months, int year) {
        int count = 0;
        for (Month month : months) {
            count += month.getDays(year);
        }
        return count;
    }
    

    or

    public int countDays(Set<String> months, int year) {
        int count = 0;
        for (String month : months) {
            int days = monthMap.get(month);
            if (month.equals(Months.FEBRUARY)) {
                days = computeDaysInFebruary(year);
            }
            count += days;
        }
        return count;
    }
    

    What if I pass something other than a month name in the set?

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

Sidebar

Related Questions

This seems like it would be a common issue to be but I don't
This question seems like it might be somewhat common, but I didn't find anything
This seems like it'd be a common question, but I cannot find it. Perhaps
This seems to be a common question but somehow none of the answers I
Seems like this would be a common question, though I could not find it
This seems like it would be fairly simple, but I've been unable to find
This seems like a repeated question but i'm not able to get my answer.
This seems like the simplest Git question, but I can't find ANYTHING on it.
This seems like a simple question to ask but, is it generally a good
This seems like a common issue but I have not found any questions that

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.