Enum values help

Discussion in 'Plugin Development' started by FozZeW, Nov 4, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    FozZeW

    Hi, i need some enum help. This is also first time i am ever using enums. I have enum and i want to load enum values/paramethers from other classes instead of write value immdetly. I just need it so i can load enum values from config file. This really doesn't have anything to do with bukkit, but might aswell. :)
     
  2. Offline

    tommycake50

    You... what?
    I don't understand this.
    I suggest you learn about enums.
     
  3. Offline

    Rocoty

    Since it is impossible to understand what you want by reading your post, I can guess that you want
    A: To get a list of all constants in an enum type.
    B: To get an enum constant from a string

    To do B, you have to do A, unless you include a redundant field with the constant's name and a constructor in the enum.

    To get to know how to do this, please look it up and try for yourself. If you still can't get the hang of it, post the code and we'll guide you through it. That's the way it should be working around here.
     
    amhokies likes this.
  4. Offline

    marwzoor

    Just make static variables in a class instead! It works just as enums, you use enums because you want something to be constant, that's why you can't change them or add new ones.
     
  5. If you want to extract enum values from a config file, do something like this:

    Code:java
    1. EnumType.valueOf(line.toUpperCase());


    This will take a String input called "line" and try to turn it into an enum value. Enums are usually all caps (e.g. ENDER_DRAGON), so you need to use toUppercase() first.
     
Thread Status:
Not open for further replies.

Share This Page