Conveniently map between enum and int / String

前端 未结 18 1866
陌清茗
陌清茗 2020-11-28 01:07

When working with variables/parameters that can only take a finite number of values, I try to always use Java\'s enum, as in

public enum BonusT         


        
18条回答
  •  长情又很酷
    2020-11-28 01:18

    You could perhaps use something like

    interface EnumWithId {
        public int getId();
    
    }
    
    
    enum Foo implements EnumWithId {
    
       ...
    }
    

    That would reduce the need for reflection in your utility class.

提交回复
热议问题