【发布时间】:2014-10-13 10:51:16
【问题描述】:
使用像这样的枚举,其中每个键都有多个值
ABBR1("long text 1", "another description 1", "yet another one 1"),
ABBR2("long text 2", "another description 2", "yet another one 2"),
//and so on...
如何通过调用getAbbreviation(descriptionText) 之类的方法来反向查找缩写(常量)?
我想我基本上是在寻找here 描述的实现,但不同的是每个 ENUM 键(常量)都有几个值,我希望它也可以与 getAbbreviation("long text 1") 一起使用与getAbbreviation("yet another one 2")...
是否有一种简单的方法可以遍历每个 ENUM(即ABBRn)的值字段,以填充巨大的地图,或者是否有更好的解决方案?
【问题讨论】:
标签: java enums lookup reverse-lookup