List of utility methods to do Reflection Constructor Get
Constructor | getConstructorOrFail(Class Finds and returns the matching constructor in class clazz , or fails with a RuntimeException if the constructor cannot be found. try { return clazz.getConstructor(argTypes); } catch (Exception e) { throw new RuntimeException("Failed to get constructor '" + clazz.getSimpleName() + "' with args " + Arrays.asList(argTypes), e); |
String | getConstructors(Class cl) Prints all constructors of a class String clName = cl.getName(); Class superClass = cl.getSuperclass(); String superClassName = ""; if (superClass != null) superClassName = superClass.getName(); StringBuilder constr = new StringBuilder( "\n\nConstructors for class: " + clName + " inherits " + superClassName + " \n"); Constructor[] constructors = cl.getDeclaredConstructors(); ... |
String[] | getConstructors(Class infoClass) Gets constructors for a class. String[] result = null; Constructor[] constructors = null; try { constructors = infoClass.getDeclaredConstructors(); } catch (SecurityException e) { return result; if ((constructors == null) || (constructors.length == 0)) ... |
List | getConstructors(Class> clazz) get Constructors List<Constructor<?>> lst = new ArrayList<Constructor<?>>(); Constructor<?>[] cotrs = clazz.getDeclaredConstructors(); for (Constructor<?> c : cotrs) { int im = c.getModifiers(); if (!Modifier.isPublic(im)) continue; lst.add(c); return lst; |
Constructor>[] | getConstructors(Class> clazz, int args) get Constructors try { List<Constructor<?>> list = new ArrayList<Constructor<?>>(); for (Constructor<?> constructor : clazz.getDeclaredConstructors()) { if (constructor.getParameterTypes().length == args) { constructor.setAccessible(true); list.add(constructor); for (Constructor<?> constructor : clazz.getDeclaredConstructors()) if (constructor.getParameterTypes().length == args) list.add(constructor); return list.toArray(new Constructor<?>[list.size()]); } catch (Throwable error) { return null; |
Set | getConstructors(Class get Constructors return createConstructorList(clazz.getConstructors());
|
List | getConstructors(Class get Constructors Constructor<?>[] constructors = clazz.getDeclaredConstructors(); List<Constructor<T>> ret = new ArrayList<Constructor<T>>(constructors.length); for (Constructor<?> constructor : constructors) { if ((modifier & constructor.getModifiers()) != 0) { @SuppressWarnings("unchecked") Constructor<T> c = (Constructor<T>) constructor; ret.add(c); return ret; |
List | getConstructors(final Class cl, final int params) Gets all the constructors in the given class or super classes, even the redefined constructors are returned. final List result = new LinkedList(); final Constructor[] ms = cl.getDeclaredConstructors(); for (int i = 0; i < ms.length; i++) { if (ms[i].getParameterTypes().length == params) { result.add(ms[i]); return result; ... |
String | getConstructorSignature(final Constructor constructor) Returns JVM type signature for a constructor. return getMethodSignature(constructor.getParameterTypes(), Void.TYPE);
|
String | getConstructorSignatureWithLongTypeNames(Constructor> init) get Constructor Signature With Long Type Names return getSignature(init, true);
|