Here you can find the source of getConstructor(Class> clazz, Class>... params)
Parameter | Description |
---|---|
params | - The parameters for the constructor |
public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... params)
//package com.java2s; //License from project: LGPL import java.lang.reflect.Constructor; public class Main { /**//w ww. j a v a 2s.co m * Attempts to get a constructor from the specified class * * @param class - The class to retrieve constructor from * @param params - The parameters for the constructor * @return The constructor if found, otherwise null */ public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... params) { if (clazz == null) { System.err.println("No class specified."); return null; } Constructor<?> constructor = null; try { constructor = clazz.getDeclaredConstructor(params); } catch (NoSuchMethodException nsme) { } if (constructor == null) { System.err.println(clazz.getName() + "does not have specified constructor"); return null; } else { try { constructor.setAccessible(true); } catch (SecurityException se) { } return constructor; } } }