Java Reflection Constructor Get getConstructor(Class targetClass, Class... parameterTypes)

Here you can find the source of getConstructor(Class targetClass, Class... parameterTypes)

Description

Gets constructor of targetClass.

License

Open Source License

Parameter

Parameter Description
targetClass from which constructor is returned
parameterTypes of constructor
T type of the target class object.

Return

constructor of targetClass or if any exception occurs

Declaration

public static <T> Constructor<T> getConstructor(Class<T> targetClass,
        Class<?>... parameterTypes) 

Method Source Code

//package com.java2s;
// License as published by the Free Software Foundation; either

import java.lang.reflect.Constructor;

public class Main {
    /**//from w w  w  .j a v  a  2 s.  c  o  m
     * Gets constructor of targetClass.
     * @param targetClass
     *            from which constructor is returned
     * @param parameterTypes
     *            of constructor
     * @param <T> type of the target class object.
     * @return constructor of targetClass or {@link IllegalStateException} if any exception occurs
     * @see Class#getConstructor(Class[])
     */
    public static <T> Constructor<T> getConstructor(Class<T> targetClass,
            Class<?>... parameterTypes) {
        try {
            return targetClass.getConstructor(parameterTypes);
        } catch (NoSuchMethodException ex) {
            throw new IllegalStateException(ex);
        }
    }
}

Related

  1. getConstructor(Class clazz, Class[] expectedTypes)
  2. getConstructor(Class cls, Class... parameterClses)
  3. getConstructor(Class cls, Class[] args)
  4. getConstructor(Class cls, Object... args)
  5. getConstructor(Class instanceType)
  6. getConstructor(Class type, Class... parameterTypes)
  7. getConstructor(Class type, Class[] parameterTypes)
  8. getConstructor(final Class theClass, final Class... parameterTypes)
  9. getConstructor(final Class clazz, final Class... parameterTypes)