Execution order of Enum in java

前端 未结 4 818
醉话见心
醉话见心 2021-01-12 10:14

I got a question about Enum.

I have an enum class looks like below

public enum FontStyle {
    NORMAL(\"This font has normal style.\"),
    BOLD(\"T         


        
4条回答
  •  [愿得一人]
    2021-01-12 11:02

    The enum instances are created only once, when the Enum class itself is loaded.

    It is very important that they are created only once, so that object identity comparison works (==). Even the object (de)serialization mechanism had to be adjusted to support this.

提交回复
热议问题