0

How do I implement generic fields to enum? Currently I'm looking for a way to hold variety native data types on single enum. e.g:

public enum Module<E>
{

    TEST_STRING("string"),
    TEST_INT(3);

    public E value;

    Module (E value)
    {
        this.value = value;
    }
}

As you may know this won't compile but what are my best alternatives to achieve this kind of structure?

homerun
  • 19,837
  • 15
  • 45
  • 70
  • 2
    [Related](http://stackoverflow.com/q/4290878/521799) – Lukas Eder Mar 21 '16 at 18:07
  • Why do you need an enum? What's wrong with a set of static fields? `static final String TEST_STRING = "string";` etc – Paul Boddington Mar 21 '16 at 18:09
  • @PaulBoddington i have followed this answer http://stackoverflow.com/a/66228/3426825 since while before and i used to hold my constants on enums – homerun Mar 21 '16 at 18:11
  • the example you're giving does not really make a lot of sense to me. The intention of enums is to group an enumerable amout of similar things. If you could probably give your real context, then it would be easier to give you a better answer. My assumption is that this answer will be an alternative to using enums in that case – Matthias Mar 21 '16 at 18:11
  • @someFolk Wow. An answer with 180 upvotes (and no downvotes) that says `Enums are perhaps the most (and, arguably, only) useful feature of Java 5+`. – Paul Boddington Mar 21 '16 at 18:13

0 Answers0