Java Reflection Constructor Get getConstructor(Class instanceType)

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

Description

get Constructor

License

Open Source License

Declaration

public static <T> Constructor<T> getConstructor(Class<T> instanceType) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;

public class Main {
    public static <T> Constructor<T> getConstructor(Class<T> instanceType) {

        Constructor<?>[] constructors = instanceType.getConstructors();

        for (Constructor<?> constructor : constructors) {

            if (constructor.getModifiers() == Modifier.PUBLIC) {
                return (Constructor<T>) constructor;
            }//from w  w w . j  a  v  a2 s .  c  o  m
        }

        return null;
    }
}

Related

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