I have multiple enum's that all have the same constructor and attributes, like this:
enum Enum1 {
A(1,2),
B(3,4);
public int a, b;
private Enum1(int a, int b) {
this.a = a;
this.b = b;
}
}
enum Enum2 {
C(6,7),
D(8,9);
public int a, b;
private Enum1(int a, int b) {
this.a = a;
this.b = b;
}
}
and so on... Unfortunately Enum1 and Enum2 already extend Enum, so it isn't possible to write a superclass they could extend. Is there another way to archive this?
Update: here comes a "real-world" example. Think of a classic rpg, where you have items, armour, weapons etc. which give you a bonus.
enum Weapon {
SWORD(3,0,2),
AXE_OF_HEALTH(3,4,1);
// bonus for those weapons
public int strength, health, defense;
private Weapon(int strength, int health, int defense) {
this.strength = strength;
this.health = health;
this.defense = defense;
}
}
enum Armour {
SHIELD(3,1,6),
BOOTS(0,4,1);
// bonus
public int strength, health, defense;
private Weapon(int strength, int health, int defense) {
this.strength = strength;
this.health = health;
this.defense = defense;
}
}