difference between Enum and enum

前端 未结 3 1544
执笔经年
执笔经年 2021-01-13 17:10

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

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-13 17:59

    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.

提交回复
热议问题