I am developing a text-based video game with two characters that are often not found together, but are very similar to each other in heart and location.
My problem is that I do not know how to initialize the enum constant through the constructor using a static final internal constant. Otherwise, the game is good .;)
Here's the dilemma:
- Enumeration constants should be defined in the first line of the enumeration, if I'm not mistaken
- The first line cannot refer to anything after it (ie "cannot refer to a field until it is defined")
How to enable this catch-22?
Here is an example of code released from a game under a non-disclosure agreement:
enum ValiantHeroWithPrincessSavingTendencies { SUPERMARIO(TYPICAL_QUOTE_FROM_MARIO), ZELDA(TYPICAL_QUOTE_FROM_ZELDA); private String aPreparedQuotePurportedToBeSpontaneousAlmostImpulsive; public String getQuoteUnderStressfulCircumstances() { return aPreparedQuotePurportedToBeSpontaneousAlmostImpulsive; } private ValiantHeroWithPrincessSavingTendencies(String quote) { aPreparedQuotePurportedToBeSpontaneousAlmostImpulsive = quote; } private static final String TYPICAL_QUOTE_FROM_ZELDA = "Have at ya!"; private static final String TYPICAL_QUOTE_FROM_MARIO = "We, wagliu'!"; }
I am trying to initialize SUPERMARIO with TYPICAL_QUOTE_FROM_MARIO, but I have not defined TYPICAL_QUOTE_FROM_MARIO yet. I think that moving a private static end field to SUPERMARIO is illegal.
source share