diff --git a/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java b/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java index 5d79f7d..04888d5 100644 --- a/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java +++ b/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -208,4 +209,52 @@ public class BeanUtil { return fieldObjectMap; } + /** + * 通过无参数构造函数返回实例 + * @param clazz + * @param + * @return + */ + public static T instantiateClass(Class clazz){ + T t = null; + try { + t = clazz.newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + return t; + } + + /** + * 通过有参数构造函数返回实例 + * @param clazz + * @param params + * @param + * @return + */ + public static T instantiateClass(Class clazz,Object... params){ + T t = null; + Class[] classes = new Class[params.length]; + for (int i=0;i