我想做这样的事情:
public class MyEnumTest {
public enum MyEnum;
private MyEnum value;
public MyEnumTest(enum e)
{
this.MyEnum = e;
this.value = this.MyEnum.values[0]//Set value to the first enum value.
}
public void setValue(MyEnum e)
{
this.value = e;
}
public MyEnum getValue()
{
return value;
}
}
并称其为:
MyEnumTest car = new MyEnumTest({HONDA, FORD, TOYOTA, HOLDEN});
MyEnumTest fruit = new MyEnumTest({APPLE, BANANA, CHERRY});
/* some operations occur*/
if (car.getValue() == car.FORD) System.out.println("Vrooom!");
if (fruit.getValue()) == fruit.APPLE) System.out.println ("Is red and round and delicious");
有什么想法吗?
对于奖励分数 - 是否可以使用枚举值设置初始值?例如类似的东西
MyEnumTest myET = new myEnumTest(new enum {RED, GREEN, BLUE, YELLOW}, BLUE);