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 7082705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:05:15+00:00 2026-05-28T07:05:15+00:00

I have two enums that cross reference each other. Each one has a constructor

  • 0

I have two enums that cross reference each other. Each one has a constructor that has a parameter for other enum.

They look something like:

SchoolEnum(ImmuneEnum value)
{
   this.immune = value;
}

ImmuneEnum(SchoolEnum value)
{
   this.school = value;
}

However depending on which Enum I call first, I can get a null value for the reference variable.

ImmunityEnum immune = ImmunityEnum.IMMUNE_KANNIC; 
SchoolEnum school = SchoolEnum.KANNIC;
System.out.println(school.getImmune())
System.out.println(immune.getSchool());

Produces the output:
null
Kannic

SchoolEnum school = SchoolEnum.KANNIC;
ImmunityEnum immune = ImmunityEnum.IMMUNE_KANNIC; 
System.out.println(school.getImmune())
System.out.println(immune.getSchool());

Produces the output:
immunekannic
null

It seems to be a bit of the “chicken and egg” problem as to when the enum is instantiated. But is there a way to have each one properly reference the other? I am considering making two singleton hashmaps that artificially cross reference the two, but is there a better idea?

  • 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-05-28T07:05:16+00:00Added an answer on May 28, 2026 at 7:05 am

    What if you passing String parameters into your constructors:

    public enum SchoolEnum {
       Kannic("immnunekannic");
       private String immune;
       public SchoolEnum (String immune) {this.immune = immune;}
       public ImmuneEnum getImmune() {
           return ImmuneEnum.valueOf(immune);
       }
    }
    
    public enum ImmnueEnum {
       immunekannic("Kannic");
       private String scholl;
       public ImmnueEnum (String school) {this.school = school;}
       public SchoolEnum getSchool() {
           return SchoolEnum.valueOf(school);
       }
    }
    

    But honestly it’s a bit strange to create this type of domain model. What’s your use case?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two applications written in Java that communicate with each other using XML
In my application, I have two equivalent enum s. One lives in the DAL,
I have the following code snippet: enum { one } x; enum { two
I have one class that declares an enumeration type as: public enum HOME_LOAN_TERMS {FIFTEEN_YEAR,
1) - i have two enums enum FixedScriptingEvent { FIXED_SCRIPTING_EVENT_NOTOUCH, FIXED_SCRIPTING_EVENT_OVER_MOVED, FIXED_SCRIPTING_EVENT_OVER_RELEASED, FIXED_SCRIPTING_EVENT_OUTSIDE_RELEASED, FIXED_SCRIPTING_EVENT_OUTSIDE_MOVED,
I have two data structures in Java: One is called DebateAssignment and has 5
I have a table with two enum columns, each enum contains about 10 possible
For example, I have two elements in an enum. I would like the first
public enum ObjectType { Country=0, Region=1, Province=2, City=3, Hotel=4 } I have two applications
For example if I have an Enum with two cases, does it make take

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.