difference between Enum and enum

前端 未结 3 1543
执笔经年
执笔经年 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.

    0 讨论(0)
  • 2021-01-13 18:08

    The method inside Enum is generic and can be used with any enum and the method inside enum is specific to that enum only.

    0 讨论(0)
  • 2021-01-13 18:10

    Enum.valueOf(Class<T>, String) is used to implement the valueOf(String) method generated into each specific enum class.

    0 讨论(0)
提交回复
热议问题