Interfaces vs. enums

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

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

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-07 00:59

    Interfaces are designed to define common behaviours, enums to define common values.

    Enum represents a real value which can be compared to another value, or stored in the database easily. You can also have a flag-enum (in C#, don't know in Java) which let you perform binary operations on enum's values (AND, OR, XOR, etc).

提交回复
热议问题