Java enum reverse look-up best practice

前端 未结 7 713
感情败类
感情败类 2020-12-04 15:07

I saw it suggested on a blog that the following was a reasonable way to do a \"reverse-lookup\" using the getCode(int) in a Java enum:

public en         


        
7条回答
  •  星月不相逢
    2020-12-04 15:43

    Obviously the map will provide constant time lookup whereas the loop won't. In a typical enum with few values, I don't see a problem with the traversal lookup.

提交回复
热议问题