静态代码块+Map消除if
public class Util {
public static Map<String, Float> map = new HashMap<>(8);
static {
map.put("A", 1.0f);
map.put("B", 2.0f);
}
public static float getPitBoxSqprice(String key) {
return map.get(key);
}
}
调用
Util.getPitBoxSqprice("A");