Why does javac add values ββ() and valueOf (String) methods to a specific type of enumeration?
This saves the class itself.
Wouldn't it be better if they were added to the Enum class?
The compiler cannot do this, since the Enum class is already compiled, and you may not use the same copy anyway.
This can be done at runtime, but you add complexity, for example. this makes class unloading more difficult for little gain.
What is the reason for this?
There is no better place to place it.
Note: Enum.valueOf(clazz, name) calls clazz.valueOf(name); , since it would be pointless to call clazz.valueOf(clazz, name); (although you can if you want to confuse people)
source share