Enum values().length vs private field

后端 未结 4 1699
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 13:12

I have enumeration like this:

public enum Configuration {
    XML(1),
    XSLT(10),
    TXT(100),
    HTML(2),
    DB(20);

    private final int id;
    pri         


        
4条回答
  •  眼角桃花
    2020-12-08 13:46

    By storing the count you're violating the DRY principle, so unless you have a very good reason, you shouldn't.

提交回复
热议问题