使用反射机制创建带构造参数的对象

使用反射机制创建带构造参数的对象

private <T> T construct(
    Class<T> clazz,
    Class<?>[] parameterTypes,
    Object[] parameterValues) throws Exception {
	
    Constructor<T> cons = clazz.getDeclaredConstructor(parameterTypes);
	
    return cons.newInstance(parameterValues);
}

posted on 2017-07-03 18:26  zyunx  阅读(692)  评论(0编辑  收藏  举报

导航