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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:33:34+00:00 2026-06-13T23:33:34+00:00

If you look in the enum api at the method name() it says that:

  • 0

If you look in the enum api at the method name() it says that:

Returns the name of this enum constant, exactly as declared in its enum declaration.
Most programmers should use the toString method in preference to this one,
as the toString method may return a more user-friendly name.
This method is designed primarily for use in specialized situations where correctness depends on getting the exact name, which will not vary from release to release.

Why is better to use toString()? I mean toString may be overridden when name() is already final. So if you use toString and someone overrides it to return a hard-coded value your whole application is down… Also if you look in the sources the toString() method returns exactly and just the name. It’s the same thing.

  • 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-13T23:33:36+00:00Added an answer on June 13, 2026 at 11:33 pm

    It really depends on what you want to do with the returned value:

    • If you need to get the exact name used to declare the enum constant, you should use name() as toString may have been overriden
    • If you want to print the enum constant in a user friendly way, you should use toString which may have been overriden (or not!).

    When I feel that it might be confusing, I provide a more specific getXXX method, for example:

    public enum Fields {
        LAST_NAME("Last Name"), FIRST_NAME("First Name");
    
        private final String fieldDescription;
    
        private Fields(String value) {
            fieldDescription = value;
        }
    
        public String getFieldDescription() {
            return fieldDescription;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

look at this fiddle: http://jsfiddle.net/ugxNK/ I want that the first list element is in
Look ath this method of ThreadPoolExcecutor: public void execute(Runnable command) { ... if (runState
My Grails application has a large number of enums that look like this: public
I have this bit of code that helps me convert enum to string and
Just because I don't know exactly where to look this up in my c++
Ok so I have a number of methods that look like this:- which sorts
I have a grid that is declared like: PlayerStatus enum { OCCUPIED, VACANT }
Look t this code plz: #include <iostream> using namespace std; int main() { enum
Look the code below. I'd like to replace USERNAME by the field name received
Look at this: $('form).submit(function (event) { $(':input.required').trigger('blur'); var num = $('.warning', this).length; alert(num);//Focus here!

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.