enum has valueOf(string)
method to get enum constant and the same type of method present in java.lang.Enum
class having name valueOf(enumClas
The reason the Enum.valueof()
method is included is that it works with any enum
. By contrast, the enum
valueof
method for a specific method only works for that specific enum
... since enum
classes cannot be used polymorphically.
Obviously the Enum.valueOf(...)
method is only really useful if you are implementing code that needs to work for multiple enum
types ... and generics don't cut it.
The method inside Enum is generic and can be used with any enum and the method inside enum is specific to that enum only.
Enum.valueOf(Class<T>, String)
is used to implement the valueOf(String)
method generated into each specific enum class.