Here you can find the source of getConstructor(Class clazz, Class[] paramTypes)
public static Constructor getConstructor(Class clazz, Class[] paramTypes)
//package com.java2s; /*// ww w .j a va2 s.c om * $Id$ * -------------------------------------------------------------------------------------- * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com * * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.txt file. */ import java.lang.reflect.Constructor; import java.lang.reflect.Method; public class Main { public static Constructor getConstructor(Class clazz, Class[] paramTypes) { return getConstructor(clazz, paramTypes, false); } /** * Returns available constructor in the target class that as the parameters specified. * * @param clazz the class to search * @param paramTypes the param types to match against * @param exactMatch should exact types be used (i.e. equals rather than isAssignableFrom.) * @return The matching constructor or null if no matching constructor is found */ public static Constructor getConstructor(Class clazz, Class[] paramTypes, boolean exactMatch) { Constructor[] ctors = clazz.getConstructors(); for (int i = 0; i < ctors.length; i++) { Class[] types = ctors[i].getParameterTypes(); if (types.length == paramTypes.length) { int matchCount = 0; for (int x = 0; x < types.length; x++) { if (paramTypes[x] == null) { matchCount++; } else { if (exactMatch) { if (paramTypes[x].equals(types[x]) || types[x].equals(paramTypes[x])) { matchCount++; } } else { if (paramTypes[x].isAssignableFrom(types[x]) || types[x].isAssignableFrom(paramTypes[x])) { matchCount++; } } } } if (matchCount == types.length) { return ctors[i]; } } } return null; } public static Class<?>[] getParameterTypes(Object bean, String methodName) { if (!methodName.startsWith("set")) { methodName = "set" + methodName.substring(0, 1).toUpperCase() + methodName.substring(1); } Method methods[] = bean.getClass().getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(methodName)) { return methods[i].getParameterTypes(); } } return new Class[] {}; } }