What are enums and why are they useful?

后端 未结 27 2097
一整个雨季
一整个雨季 2020-11-22 07:06

Today I was browsing through some questions on this site and I found a mention of an enum being used in singleton pattern about purported thread safety benefits

27条回答
  •  攒了一身酷
    2020-11-22 07:35

    Enums are like classes. Like class, it also has methods and attributes.

    Differences with class are: 1. enum constants are public, static , final. 2. an enum can't be used to create an object and it can't extend other classes. But it can implement interfaces.

提交回复
热议问题