📜  java 可选参数 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:27.283000             🧑  作者: Mango

代码示例6
@SuppressWarnings("unchecked")
static  T getParm(Map map, String key, T defaultValue) {
  return (map.containsKey(key)) ? (T) map.get(key) : defaultValue;
}

void foo(Map parameters) {
  String a = getParm(parameters, "a", "");
  int b = getParm(parameters, "b", 0);
  // d = ...
}

foo(Map.of("a","a",  "b",2,  "d","value"));