通过反射按参数类型查找适当的构造方法
//package com.nowjava; import java.lang.reflect.Constructor; /*N o w J a v a . c o m - 时代Java*/ import java.util.List; public class Main { public static Constructor<?> findProperConstructor(Class<?> clazz, List<Class<?>> types) { Constructor<?>[] constructors = clazz.getConstructors(); for (Constructor<?> constructor : constructors) { if (isProperConstructor(constructor, types)) { return constructor; } } /* from 时 代 J a v a - nowjava.com*/ return null; } protected static boolean isProperConstructor( Constructor<?> constructor, List<Class<?>> types) { Class<?>[] constructorParams = constructor.getParameterTypes(); if (constructorParams.length != types.size()) { return false; } for (int i =