ClassUtil.java代码解读

来源:互联网 发布:java unix timestamp 编辑:程序博客网 时间:2024/06/05 00:49
public static <T> T getMappingSource(MappingSource<T> source) {Class<T> clazz = source.getClazz();Map<String, String> map = source.getMapping();Map<String, String> info = source.getInfo();Method[] methods = clazz.getMethods();T t = null;try {t = clazz.newInstance();} catch (InstantiationException | IllegalAccessException e) {// TODO Auto-generated catch blocke.printStackTrace();}for (Method method : methods) {String name = method.getName();if (name.startsWith("set")) {name = lowerCaseFirstWord(name.substring(3));String arg = info.get(map.get(name));if (arg != null) {try {method.invoke(t, arg);} catch (IllegalAccessException | IllegalArgumentException| InvocationTargetException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}return t;}

1.使用两个map类的原因,防止类中元素名与映射的不一致

2.StringUtil的常用方法

3.反射的应用

0 0
原创粉丝点击