Interfaces vs. enums

前端 未结 5 1444
名媛妹妹
名媛妹妹 2021-02-07 00:24

Between interfaces and enums, which is better for declaring constants? Why is it so?

5条回答
  •  孤独总比滥情好
    2021-02-07 00:55

    If you work with Java 5 or newer then Enum are the way to go. The only exception is if your list of const is open and can be extended. Enums can not be extended. Another exception is if it are single values like a MAX_INTEGER.

提交回复
热议问题