Thursday, 15 April 2010

java - Accessing superclass variables from an enum -


Does any one set the variable held in an enum parent / superclass from within an enum? (The following is not a compilation, but it shows what I am trying to achieve) ....

  Class MyClass {Object Type Type; Some values ​​of string; Public Zero Set Type (object type this type) {type = thisType; } Ang object object {ball {@ override public watch set value (someValue = "this is a ball"; // some values ​​are not accessible from here}}, batting {@ override public watch set value (someValue = "this is a bat"; // some values ​​are not accessible here}}, net {@ override public video set value (someValue = "this is a net"; // some value is not accessible from here}}; Public abstract zero set value (); }}  

Then, something like this:

  MyClass myObject = new MyClass (); MyObject.setType (ObjectType.ball);  

After the above, the 'someValue' string of myObject should now be set to 'this one ball'.

Is there any way to do this?

You can do the following, if you want that MyClass.someValue equals some value of enum , But as some value can be obtained from eclipse, I did not want to disturb some value on myclus, and when necessary it should be obtained from the NAM.

  Public class MyClass {Object type type; Some values ​​of string; Public Zero Set Type (object type this type) {this.Type = thisType; This.someValue = thisType.getSomeValue (); } Angle object type {ball ("this is a ball"), ball ("this is a bat"), net ("this is a net"); Private last string someValue; Object type (string some value) {this.someValue = someValue; } Get some value for the public string () {return someValue; }}}  

No comments:

Post a Comment