Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8516915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:33:25+00:00 2026-06-11T05:33:25+00:00

I am designing a text-only videogame with two characters not often seen together, yet

  • 0

I am designing a text-only videogame with two characters not often seen together, yet very much alike in heart and disposition.

My problem is that I don’t know how to initialise an enum constant through a constructor using a static final inner constant. Otherwise the game is good to go. 😉

Here’s the dilemma:

  1. The enum constants must be defined in the first line of the enum, if I am not mistaken
  2. The first line can’t refer to anything coming after it (i.e. “cannot reference a field before it is defined”)

How do I resolve this catch-22?

Here some sample code released from the game under 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 initialise SUPERMARIO using TYPICAL_QUOTE_FROM_MARIO but I haven’t defined TYPICAL_QUOTE_FROM_MARIO yet. Moving the private static final field before SUPERMARIO is illegal, I think.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:33:25+00:00Added an answer on June 11, 2026 at 5:33 am

    The only viable options are to either a) move your constants to another class or b) just put your constants directly into the value initializers.

    If you move your constants, you can make the class a static class in the enum:

    enum ValiantHeroWithPrincessSavingTendencies {
      SUPERMARIO(Quotes.TYPICAL_QUOTE_FROM_MARIO),
      ZELDA(Quotes.TYPICAL_QUOTE_FROM_ZELDA);
    
      private String aPreparedQuotePurportedToBeSpontaneousAlmostImpulsive;
    
      public String getQuoteUnderStressfulCircumstances() {
        return aPreparedQuotePurportedToBeSpontaneousAlmostImpulsive;
      }
    
      private ValiantHeroWithPrincessSavingTendencies(String quote) {
        aPreparedQuotePurportedToBeSpontaneousAlmostImpulsive = quote;
      }
    
      private static class Quotes {
        private static final String TYPICAL_QUOTE_FROM_ZELDA = "Have at ya!";
        private static final String TYPICAL_QUOTE_FROM_MARIO = "We, wagliu'!";
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a project in which i am designing a Text Editor application
I am designing an app which will present large amounts of text that is
Im designing a website, and often I need to present information in a nice
While designing a new WPF application I noticed exceptions not being thrown during data
I'm designing a system to process plain text files, one of its features will
I am designing a program that contains two JPanels within a JFrame, one is
Because of my native language good for web designing fonts are not available. I
I am designing a text field which I want to be appear vertically-middle of
I am designing a form where I need to input two individuals, both fields
I am designing a simple app from tutorials that I have seen, and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.