Java Reflection Constructor Get getConstructor(Class clazz, boolean declared, Class... args)

Here you can find the source of getConstructor(Class clazz, boolean declared, Class... args)

Description

get Constructor

License

LGPL

Declaration

public static Constructor<?> getConstructor(Class<?> clazz, boolean declared, Class<?>... args) 

Method Source Code


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

import java.lang.reflect.Constructor;

public class Main {
    public static Constructor<?> getConstructor(Class<?> clazz, boolean declared, Class<?>... args) {
        try {/*from   w  ww. j  a  v a2  s  .co m*/
            Constructor<?> constructor = null;

            if (declared) {
                constructor = clazz.getDeclaredConstructor(args);
                constructor.setAccessible(true);
            } else
                constructor = clazz.getConstructor(args);

            return constructor;
        } catch (Throwable error) {
            return null;
        }
    }
}

Related

  1. getConstructor(Class clazz, Class[] paramTypes)
  2. getConstructor(Class cls, Class[] args)
  3. getConstructor(Class clz, Class expectedTypes[])
  4. getConstructor(Class type, Class[] argTypes)
  5. getConstructor(Class c, Class[] args)
  6. getConstructor(Class clazz, Class... args)
  7. getConstructor(Class clazz, Class... args)
  8. getConstructor(Class clazz, Class... parameterTypes)
  9. getConstructor(Class clazz, Class... parameterTypes)