changing the guts of an enum value

Discussion in 'Java' started by Aryeh M. Friedman, May 2, 2005.

  1. 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 {

    private foo(int val)

    public void setVal(int val)

    public int getVal()
    return Val;

    private int Val;

    public static void main(String [] arg)

    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.
    Aryeh M. Friedman, May 2, 2005
    1. Advertisements

  2. Aryeh M. Friedman

    Alan Moore Guest

    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).
    Alan Moore, May 2, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.