这是我的代码。基本上我试图从我的方法返回一个 Map。intToEnumMap
但是编译器不允许这样做。为什么编译器不能推断我的方法的返回类型?
public enum INVALIDTHRESHOLDSTATE{
ONE(0,GAUGE_MIN_LOWER_THRESHOLD1_MESSAGE),
TWO(1,GAUGE_THRESHOLD1_LOWER_THRESHOLD2_MESSAGE),
THREE(2,GAUGE_THRESHOLD2_LOWER_MAX_MESSAGE);
private static final Map<Integer,INVALIDTHRESHOLDSTATE> intToEnum = new HashMap<Integer, INVALIDTHRESHOLDSTATE>();
static {
int i=0;
for (INVALIDTHRESHOLDSTATE invalidState : values()){
i++;
intToEnum.put(Integer.valueOf(i), invalidState);
}
}
private int value;
private String message;
private INVALIDTHRESHOLDSTATE(int value,String message){
this.value = value;
this.message = message;
}
public int getValue() {
return value;
}
public String getString() {
return message;
}
// Generic method
public static <K,V> Map<K,V> intToEnumMap() {
return intToEnum; //doesn't compile
^^^^^^^^^
}
}