我正在做一個口袋妖怪類型的枚舉。每種類型都具有強度,弱點和免疫力類型。我試圖將類型傳遞到不同的數組中,這些數組存儲每種類型的優點和缺點。如何將數組傳遞給枚舉中的構造函數?
我知道我可以定義數組作爲
int [] x = {1, 2, 3, 88};
而且我試過同爲傳遞一個arrray: -
// For the sake of simplicity, all types have the same parameters for now...
public enum Type {
NORMAL ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
FIGHTING ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
FLYING ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
POISON ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
GROUND ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
ROCK ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
BUG ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
GHOST ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
STEEL ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
FIRE ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
WATER ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
GRASS ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
ELECTRIC ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
PHYSIC ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
ICE ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
DRAGON ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
DARK ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST}),
FAIRY ({Type.STEEL, Type.PHYSIC}, {Type.FIGHTING, Type.POISON}, {Type.GHOST});
private Type [] weak, strong, ineffective;
Type (Type [] weak, Type [] strong, Type [] ineffective) {
this.weak = weak;
this.strong = strong;
this.ineffective = ineffective;
}
}
我的IDE,BlueJ的,說:「非法啓動表達」。
如果不是這樣,我怎麼能將數組傳遞給枚舉的構造函數?
你可能應該看一下'EnumSet' – 2014-12-03 06:59:06