How to retrieve Enum name using the id?

前端 未结 11 1660
一整个雨季
一整个雨季 2020-12-05 13:11

I have the enum as:

public enum EnumStatus {

    PASSED(40L, \"Has Passed\"),
    AVERAGE(60L, \"Has Average Marks\"),
    GOOD(80L, \"Has Good         


        
11条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 13:59

    public static EnumStatus getById(long id)
    {
      for (EnumStatus e : EnumStatus.values())
      {
        if (id == e.getId()) return e;
      } 
      throw new IllegalArgumentException("oh no");
    }
    

提交回复
热议问题