We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

add values to enums or change string

I was wondering if it's possible to change or add values to enum types? Such as changing the string "This is a msg" or add additional value to the type test.
May I have some tips?

public enum Test {
        VALUE("This is a msg");
                
        private String x;
        
        Test (String y) {
            setX(y);
        }
        public void setX(String y) {
            x = y;
        }            
        public String getX(){        
            return x;
        }
    }
2
Contributors
1
Reply
2 Hours
Discussion Span
5 Years Ago
Last Updated
2
Views
rugae
Light Poster
27 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I don't think you can add enum values. By definition, enum values are constant:

So when should you use enums? Any time you need a fixed set of constants.

From http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html

Have a look at that page, it could help.

dwks
Posting Whiz in Training
269 posts since Nov 2005
Reputation Points: 185
Solved Threads: 28
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.3109 seconds using 2.76MB