Java Reflection Constructor Get getConstructor(Class theClass, Class[] paramTypes)

Here you can find the source of getConstructor(Class theClass, Class[] paramTypes)

Description

get Constructor

License

Apache License

Declaration

public static Constructor<?> getConstructor(Class<?> theClass, Class<?>[] paramTypes) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Constructor;

public class Main {
    public static Constructor<?> getConstructor(Class<?> theClass, Class<?>[] paramTypes) {
        Constructor<?> constructor = null;

        try {/*  w  w  w.  j a  va  2  s  .com*/
            constructor = theClass.getDeclaredConstructor(paramTypes);
            constructor.setAccessible(true);
        } catch (NoSuchMethodException | SecurityException e) {
        }

        if (constructor == null) {
            Class<?> superClasss = theClass.getSuperclass();

            if (superClasss != null)
                constructor = getConstructor(superClasss, paramTypes);
        }

        return constructor;
    }
}

Related

  1. getConstructor(Class clazz, Object[] parameters)
  2. getConstructor(Class cls, Class[] signature)
  3. getConstructor(Class cls, Object... parameters)
  4. getConstructor(Class klass, Class... parameterTypes)
  5. getConstructor(Class sourceClass, boolean isFindDeclaredConstructor, boolean isUpwardFind, Class... constructorParameterTypes)
  6. getConstructor(Class type, Constructor c)
  7. getConstructor(Class type, Object[] args)
  8. getConstructor(Class type, Class[] givenTypes)
  9. getConstructor(Class aClass)