java - "extending" enum -


I have more than one value that all have the same constructor and attributes, such as:

  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 are already expanding to Enum, so they could expand, writing a super class is not possible.

Update: Here's an example of a "real world". Think of a classic RPG, where you have items, armor, weapons, etc. that give you a bonus.

  enam weapon {sword (3,0,2), auxodoaphhhlhl (3, 4, 1); // Bonuses for those weapons public int strength, health, defense; Personal Weapons (int strength, int health, int defense) {This. Strength = strength; this. Health = health; This.defense = Rescue; }} Enum armor {SHIELD (3,1,6), boot (0,4,1); // Bonus Public Self-Strength, Health, Defense; Personal Weapons (int strength, int health, int defense) {This. Strength = strength; this. Health = health; This.defense = Rescue; }}    

Expand Enums Enum Although they can not raise anything else, They can implement the interface.

You can implement them in a common interface, and insert your getA (), getB () methods on the interface.

Comments