Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Creating a dynamic ENUM object?

800467Dec 28 2007 — edited Dec 28 2007
Hi all,

I have the requirement to add a new XYZ object to a list of XYZ - as in: List<XYZ> xyz = new ArrayList<XYZ>();

Within the XYZ enum I currently have the following object that can be created e.g.:
FirstObject()
    {
        public String displayString()
        {
            return "Some text";
        }
    }
So what I want to do is something like (by definining a constructor for the enum which takes in a String as an argument:
SecondObject()
    {
        public String displayString(userString)
        {
            return userString;
        }
    }

xyz.add(Function.NEW_ENUM("userVar"));
I need to be able to create a new ENUM on the fly (called NEW_ENUM) which takes in a the String, and add that to the ENUM list - is this possible or does this defeat the whole point of using the ENUM as a constant? Which I suspect it does.



Thanks for any info...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 25 2008
Added on Dec 28 2007
3 comments
473 views