【java8】获取指定方法名的结果集

public String getFieldData(List<?> list, String declaredMethod) {
  List<String> result = list.stream().map(r -> {
    try{
      return r.getClass().getDeclaredMethod(declaredMethodName).invoke(r);
    } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
      log.error("获取方法失败", e);
      return null;
    }
  }).filter(Objects::nonNull).map(r -> (String) r).collect(Colletors.toList());
  return String.join(",", list);
}
上一篇:vue.js get current url


下一篇:Java8新特性-新时间和日期API