I have this code and I want to call a specific element of an array:
public class Game{
...
public final Equipment[] equipment= {new Suit(this), new Sword(this), new Shield(this)};
...
}
Usually you call it like this game.equipment[0]
but I want to call it like this game.equipment[Suit]
.
I don't want to use getters like
public Equipment getSuit() {return equipment[0];}
Couldn't find anything via Google.
My idea was
public final Equipment suit = equipment[0];
but then I have to use game.suit
and I don't want that.
EDIT: Thank you for your answers and help. My solution:
public final Enhancement[] enhancements = {new Suit(this), new Sword(this), new Shield(this)};
public static final int Suit = 0;
public static final int Sword = 1;
public static final int Shield = 2;
In other classes I refer with this:
import static pp.frame.model.worlds.GameWorld.Suit;
world.equipment[Suit].apply();
I know that this is NOT beautiful but it gets the job done and my prof only wanted it to look like this.