Q:

Accessing superclass variables from an enum

Is there any way to set a variable held in an enums parent/superclass from within an enum itself?  (The following doesn't compile, but illustrates what I'm attempting to achieve)....
class MyClass{

    ObjectType type;        
    String someValue;

    public void setType(ObjectType thisType){

        type = thisType;

    } 

    enum ObjectType {

        ball{
            @Override
            public void setValue(){
                someValue = "This is a ball";  //Some value isn't accessible from here
            }
        },
        bat{
            @Override
            public void setValue(){
                someValue = "This is a bat";  //Some value isn't accessible from here
            }
        },

        net{
            @Override
            public void setValue(){
                someValue  = "This is a net";  //Some value isn't accessible from here
            }
        };

        public abstract void setValue();
    }

}

Then, something like so:
MyClass myObject = new MyClass();
myObject.setType(ObjectType.ball);

After doing the above, the 'someValue' string of the myObject should now be set to 'This is a ball'.
Is there any way to do this?

A:

A nested enum type is implicitly static (see Are java enum variables static?). That includes enum types declared as inner classes, so they can't access instance fields of the outer class.
You can't do what you're trying to do with an enum, you'll have to model that as a normal class.

A:

You could do the following, if you want MyClass.someValue to equal the someValue of the enum, but as someValue can be retrieved from the enum I'd not bother having someValue on MyClass at all, and just retrieve it from the enum when required
public class MyClass {
    ObjectType type;
    String someValue;

    public void setType(ObjectType thisType) {
        this.type = thisType;
        this.someValue = thisType.getSomeValue();
    }

    enum ObjectType {
        ball ("This is a ball"),
        bat ("This is a bat"),
        net ("This is a net");

        private final String someValue;

        ObjectType(String someValue) {
            this.someValue = someValue;
        }

        public String getSomeValue() {
            return someValue;
        }
    }
}

