0

How do you add more values to enums in java, I made some code to give an idea of what I'm going for but I know it doesn't work.

public class Types 
{
    public enum PieceTypes
    {}

    public void addTypes(String a)
    {
        PieceTypes = PieceTypes.values() + a;
    }

}

I have no idea where to start, please help.

  • 2
    You have a similar question here https://stackoverflow.com/questions/478403/can-i-add-and-remove-elements-of-enumeration-at-runtime-in-java – Isac Jun 10 '17 at 16:42

1 Answers1

1

The enum should be defined in compile time. yo can not change enum at run time.
You can use a List<String> or a Map<String,integer> and using simple string literals to simulate a dynamic enumeration.

m.ghoreshi
  • 782
  • 5
  • 12