Java Reflection Constructor Get getConstructor(Class clazz)

Here you can find the source of getConstructor(Class clazz)

Description

Returns the empty argument constructor of the class.

License

Apache License

Declaration

public static <T> Constructor<T> getConstructor(Class<T> clazz)
        throws SecurityException, NoSuchMethodException 

Method Source Code


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

import java.lang.reflect.Constructor;

public class Main {
    public static Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0];

    /**/*www  .j ava  2  s.  c  o m*/
     * Returns the empty argument constructor of the class.
     */
    public static <T> Constructor<T> getConstructor(Class<T> clazz)
            throws SecurityException, NoSuchMethodException {
        if (clazz == null) {
            throw new IllegalArgumentException("class cannot be null");
        }
        Constructor<T> cons = clazz.getConstructor(EMPTY_CLASS_ARRAY);
        cons.setAccessible(true);
        return cons;
    }
}

Related

  1. getConstructor(Class type, Constructor c)
  2. getConstructor(Class type, Object[] args)
  3. getConstructor(Class type, Class[] givenTypes)
  4. getConstructor(Class aClass)
  5. getConstructor(Class cl, Class... params)
  6. getConstructor(Class clazz, Class... parameterTypes)
  7. getConstructor(Class clazz, Class[] expectedTypes)
  8. getConstructor(Class cls, Class... parameterClses)
  9. getConstructor(Class cls, Class[] args)