Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

changing the guts of an enum value

Thread view: 
Aryeh M. Friedman - 02 May 2005 00:08 GMT
Lets say I have something like this:

// yes this compiles I cut and pasted this from a example I wrote
// specificallu for this post
public enum foo {
        Ack(10);

        private foo(int val)
        {
                setVal(val);
        }

        public void setVal(int val)
        {
                Val=val;
        }

        public int getVal()
        {
                return Val;
        }

        private int Val;

        public static void main(String [] arg)
        {
                System.out.println(Ack.getVal());
                Ack.setVal(20);
                System.out.println(Ack.getVal());
        }
}

is there any reason why I shouldn't do something like it, assume that
main() is for debugging only and the real code has the actual user's of
the enum values calling get/setVal.

The idea here is I am writting a parser that needs to reconize different
types of delims (depending on input type) and came up with the idea of
just redefining an enum thus the code is still symbolic but dynamic.
Alan Moore - 02 May 2005 19:17 GMT
>Lets say I have something like this:
>
[quoted text clipped - 35 lines]
>types of delims (depending on input type) and came up with the idea of
>just redefining an enum thus the code is still symbolic but dynamic.

I don't see any reason why you shouldn't do that.  In the "Typesafe
Enums" item in _Effective Java_, Josh Bloch encourages using enums as
"starter" classes, which may eventually evolve into more complex
classes.  That was in reference to his home-grown enum pattern, but I
think it still applies to the built-in enums (which were also written
by Bloch, BTW).


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.