Changing Enum at Runtime Java

后端 未结 2 435
花落未央
花落未央 2021-01-20 02:08

Is there any way to add elements to a built in enum class in Java?

My question is similar to Can I add and remove elements of enumeration at runtime in Java, but tha

2条回答
  •  借酒劲吻你
    2021-01-20 02:34

    You can change a enum at runtime my altering the class at runtime before you load it. You can either compile an altered enum at runtime and load it or you can use byte code manipulation to alter it.

    In short, include all the enums you need and you should never need to add to them at runtime. e.g. if there are only seven days in a weeks, include all of them at compile time.

提交回复
热议问题