我正在使用我的Eclipse项目中的一些现有代码。在以下称为cardTypeForPbfValue()
的方法中,即使我在调试代码时可以看到它,但仍无法找到HashMap
中的密钥。从传入的密钥中找不到散列表中的关联值
[1=ATM, 2=DEBIT, 3=CREDIT, 4=PAYROLL]
我不知道为什么,当我路过的值为3以下cardTypeForPbfValue()
我不能得到的CREDIT
关联的值:pbfValueMap
如下填充。我实际上获得了NULL
的值。
任何帮助/方向,将不胜感激。
这是我的工作代码:
public static enum CardType {
CREDIT(3),
ATM(1),
DEBIT(2),
PAYROLL(4);
CardType(int pbfValue) {
this.pbfValue = (short) pbfValue;
}
public static HashMap<Short, CardType> pbfValueMap = new HashMap<Short, CardType>();
static {
for (CardType cardType : CardType.values()) {
short value = cardType.pbfValue;
pbfValueMap.put(cardType.pbfValue, cardType);
}
}
public static CardType **cardTypeForPbfValue**(int pbfValue) {
CardType returnValue = pbfValueMap.get(pbfValue);
if (returnValue == null) {
returnValue = DEBIT;
}
return returnValue;
}
public short pbfValue;
}
它是int,先把它缩短。 – 2013-05-08 17:41:49