Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have you considered extending a class that takes <code>Enum</code> as a generic parameter? It is an amazingly flexible mechanism.</p> <pre><code>public class Entity&lt;E extends Enum&lt;E&gt; &amp; Entity.IE&gt; { // Set of all possible entries. // Backed by an EnumSet so we have all the efficiency implied along with a defined order. private final Set&lt;E&gt; all; public Entity(Class&lt;E&gt; e) { // Make a set of them. this.all = Collections.unmodifiableSet(EnumSet.&lt;E&gt;allOf(e)); } // Demonstration. public E[] values() { // Make a new one every time - like Enum.values. E[] values = makeTArray(all.size()); int i = 0; for (E it : all) { values[i++] = it; } return values; } // Trick to make a T[] of any length. // Do not pass any parameter for `dummy`. // public because this is potentially re-useable. public static &lt;T&gt; T[] makeTArray(int length, T... dummy) { return Arrays.copyOf(dummy, length); } // Example interface to implement. public interface IE { @Override public String toString(); } } class Thing extends Entity&lt;Thing.Stuff&gt; { public Thing() { super(Stuff.class); } enum Stuff implements Entity.IE { One, Two; } } </code></pre> <p>You can pass the nature of your implementation up to the parent class in many different ways - I use <code>enum.class</code> for simplicity.</p> <p>You can even make the <code>enum</code> implement an interface as you can see.</p> <p>The <code>values</code> method is for demonstration only. Once you have access to the <code>Set&lt;E&gt;</code> in the parent class you can provide all sorts of functionality just by extending <code>Entity</code>.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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