List of utility methods to do Reflection Constructor Get
String | getConstructorSimpleName(Constructor> constructor) get Constructor Simple Name final String name = constructor.getName(); return getConstructorSimpleName(name); |
List | getConstructorsOfLength(final Class clazz, final int length) get Constructors Of Length List<Constructor> fixedLengthConstructors = new ArrayList<Constructor>(1); Constructor[] constructors = clazz.getDeclaredConstructors(); for (int i = 0; i < constructors.length; i++) { if (!Modifier.isPublic(constructors[i].getModifiers())) continue; Class[] parameterTypes = constructors[i].getParameterTypes(); if (parameterTypes.length == length) fixedLengthConstructors.add(constructors[i]); ... |
Constructor | getConstructorWithArgs(Class Looks for a constructor matching the argument given. if (clazz != null) { Constructor<?>[] constructors = clazz.getConstructors(); for (Constructor<?> constructor : constructors) { if (constructor.getParameterTypes().length == args.length) { Class<?>[] pType = constructor.getParameterTypes(); for (int i = 0; i < pType.length; i++) { if (!pType[i].equals(args[i].getClass())) { continue; ... |
Constructor | getConstructorWithLeastParametersFromList( ArrayList get Constructor With Least Parameters From List Constructor planBConstructor = Object.class.getDeclaredConstructors()[0]; Constructor retVal; if (!constructorsFromType.isEmpty()) { int index = 0; retVal = constructorsFromType.get(index); index++; while (retVal.getExceptionTypes().length > 0 && index < constructorsFromType.size()) { retVal = constructorsFromType.get(index); ... |
Constructor | getConstructorWithNoParams(Class clazz) get Constructor With No Params for (Constructor constructor : clazz.getConstructors()) { if (constructor.getParameterTypes().length == 0) { if (Modifier.isPrivate(constructor.getModifiers()) || Modifier.isProtected(constructor.getModifiers())) { constructor.setAccessible(true); return constructor; return null; |
Constructor | getConstructorWithReflection(String className, Class>... parameterTypes) get Constructor With Reflection Class loadedClass = Class.forName(className);
return loadedClass.getConstructor(parameterTypes);
|