To convert an ordinal into its enum represantation you might want to do this:
ReportTypeEnum value = ReportTypeEnum.values()[ordinal];
Please notice the array bounds.
Note that every call to values()
returns a newly cloned array which might impact performance in a negative way. You may want to cache the array if it's going to be called often.
Code example on how to cache values()
.
This answer was edited to include the feedback given inside the comments
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…