I have the enum
as:
public enum EnumStatus {
PASSED(40L, \"Has Passed\"),
AVERAGE(60L, \"Has Average Marks\"),
GOOD(80L, \"Has Good
Sometimes the enum's ordinal has a clear relationship with this kind of ids, enabling a neat way to get O(1) in these methods. In your code, it is clear that
EnumStatus.X = 40 + 20 * ordinal
,
so you can leverage the static array that is generated under the hoods.
public static EnumStatus fromId(Long id) {
int index = (id - 40L) / 20L;
return values()[index];
}