Note that there are some explanatory texts on larger screens.

plurals
  1. POJava enum association
    primarykey
    data
    text
    <p>I am trying to create a scenario where by an enum constant in <code>enum class A</code> has associated sub <code>enum class B</code> and <code>enum class C</code> containing their own constants. The constants in <code>enum class B</code> and <code>enum class C</code> group subsets of constants from <code>enum class D</code>. Below is a basically what I am trying to achieve:</p> <pre><code>enum A { CONST_1 ("const_1", B), // B is the associated enum CONST_2 ("const_2", C); // C in the associated enum private final String strVal; private final Enum associatedEnum; private A (String strVal, Enum associatedEnum) { this.strVal = strVal; this.associatedEnum = associatedEnum; } public Enum getAssociatedEnum() { return this.associatedEnum; } public String toString() { return this.strVal; } // Associated Enum contained subset of grouped constants enum B { CONST_3 (D.CONST_7.toString()), CONST_4 (D.CONST_8.toString()); private final String strVal; private B (String strVal) { this.strVal = strVal; } public String toString() { return this.strVal; } } // Associated Enum contained subset of grouped constants enum C { CONST_5 (D.CONST_9.toString()), CONST_6 (D.CONST_10.toString()); private final String strVal; private C (String strVal) { this.strVal = strVal; } public String toString() { return this.strVal; } } } // Separate Enum containing all ungrouped constants enum D { CONST_7 ("const_7"), CONST_8 ("const_8"); CONST_9 ("const_9"), CONST_10 ("const_10"); private final String strVal; private D (String strVal) { this.strVal = strVal; } public String toString() { return this.strVal; } } </code></pre> <p>Obviously this syntax doesn't work OOTB because you cannot pass classes in Java this way. But can anyone suggest a way in which I could achieve this?</p> <p>I am hoping to use it to validate static structured groupings in a client-side application.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload