Java – using inner classes in Java – enum

enumsinner-classesjava

I have a very specific issue that has to do with an inner class. Let me show you some sample code:

class Foo {
    MYOPTIONS temp;

    public static enum MYOPTIONS {
        OPTION1, OPTION2, OPTION3;
    } 
}

So this enumeration is inside the class Foo. Now what I want to do is set the temp variable as one of the three options, but do that outside the class Foo, let's say from a class called External. Unfortunately I cannot have a set method to do that because External.setTemp (MYOPTIONS.OPTION1) is not valid, as the enum is not visible in class external.
So the only thing I could come up with is have three methods in class Foo:

public void setTempOption1 () {this.temp=MYOPTIONS.OPTION1;}
public void setTempOption2 () {this.temp=MYOPTIONS.OPTION2;}
public void setTempOption3 () {this.temp=MYOPTIONS.OPTION3;}

Obviously the other option is to change the enumeration and not have it as an inner class.
Are there any other options that I am missing?
Thanks

Best Solution

class ContainsInnerEnum {
    MYOPTIONS temp;

    public enum MYOPTIONS {
        OPTION1, OPTION2, OPTION3;
    } 
}

class EnumTester {
    public void test () {
        ContainsInnerEnum ie = new ContainsInnerEnum ();
        // fail:
        // ie.temp = MYOPTIONS.OPTION1;
        // works:
        ie.temp = ContainsInnerEnum.MYOPTIONS.OPTION1;
    }       
}

The whole name of the MYOPTIONS contains the embedding class name.