Java Reflection Constructor Get getConstructor(Class clazz, Class... params)

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

Description

Returns the constructor

License

Open Source License

Parameter

Parameter Description
clazz The class
params The Constructor parameters

Return

The Constructor or null if there is none with these parameters

Declaration

@SuppressWarnings("unused")
@Nullable
public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... params) 

Method Source Code


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

import javax.annotation.Nullable;
import java.lang.reflect.Constructor;

public class Main {
    /**/*from  w  w w .  ja v  a2s .com*/
     * Returns the constructor
     *
     * @param clazz  The class
     * @param params The Constructor parameters
     *
     * @return The Constructor or null if there is none with these parameters
     */
    @SuppressWarnings("unused")
    @Nullable
    public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... params) {
        try {
            return clazz.getConstructor(params);
        } catch (NoSuchMethodException e) {
            return null;
        }
    }
}

Related

  1. getConstructor(Class clazz, boolean declared, Class... args)
  2. getConstructor(Class clazz, Class... args)
  3. getConstructor(Class clazz, Class... args)
  4. getConstructor(Class clazz, Class... parameterTypes)
  5. getConstructor(Class clazz, Class... parameterTypes)
  6. getConstructor(Class clazz, Class... params)
  7. getConstructor(Class clazz, Object... args)
  8. getConstructor(Class clazz, Object[] parameters)
  9. getConstructor(Class cls, Class[] signature)