List of utility methods to do Reflection Constructor Get
Constructor> | getConstructor(Class> klass, Class>... parameterTypes) get Constructor Constructor<?>[] constructors = klass.getConstructors(); SEARCH: for (Constructor<?> c : constructors) { Class<?>[] constructorParameterTypes = c.getParameterTypes(); if (constructorParameterTypes.length != parameterTypes.length) continue SEARCH; for (int i = 0; i < parameterTypes.length; i++) { if (!constructorParameterTypes[i].isAssignableFrom(parameterTypes[i])) continue SEARCH; ... |
Constructor> | getConstructor(Class> sourceClass, boolean isFindDeclaredConstructor, boolean isUpwardFind, Class>... constructorParameterTypes) get Constructor Constructor<?> method = null; try { method = isFindDeclaredConstructor ? sourceClass.getDeclaredConstructor(constructorParameterTypes) : sourceClass.getConstructor(constructorParameterTypes); } catch (NoSuchMethodException e1) { if (isUpwardFind) { Class<?> classs = sourceClass.getSuperclass(); while (method == null && classs != null) { ... |
Constructor> | getConstructor(Class> theClass, Class>[] paramTypes) get Constructor Constructor<?> constructor = null; try { constructor = theClass.getDeclaredConstructor(paramTypes); constructor.setAccessible(true); } catch (NoSuchMethodException | SecurityException e) { if (constructor == null) { Class<?> superClasss = theClass.getSuperclass(); ... |
Constructor> | getConstructor(Class> type, Constructor> c) get Constructor if (c == null || Modifier.isPublic(type.getModifiers())) { return c; Constructor<?> cp = null; Class<?> sup = type.getSuperclass(); if (sup != null) { try { cp = sup.getConstructor(c.getParameterTypes()); ... |
Constructor> | getConstructor(Class> type, Object[] args) get Constructor for (Constructor<?> c : type.getConstructors()) { if (instanceOfs(c.getParameterTypes(), args)) return c; return null; |
Constructor | getConstructor(Class Returns the constructor where the formal parameter list matches the givenTypes argument. return type.getConstructor(givenTypes);
|
Constructor | getConstructor(Class get Constructor Constructor constr = aClass.getDeclaredConstructor(); try { constr.setAccessible(true); return constr; } catch (Exception ex) { return aClass.getConstructor(); |
Constructor | getConstructor(Class Returns the specified declared constructor, making it accessible. try { Constructor<T> result = cl.getDeclaredConstructor(params); result.setAccessible(true); return result; } catch (Exception e) { throw new RuntimeException("Unexpected exception: " + e, e); |
Constructor | getConstructor(Class Returns the empty argument constructor of the class. if (clazz == null) { throw new IllegalArgumentException("class cannot be null"); Constructor<T> cons = clazz.getConstructor(EMPTY_CLASS_ARRAY); cons.setAccessible(true); return cons; |
Constructor | getConstructor(Class Returns a public constructor of the given class with the given parameter types. try { if (parameterTypes != null && parameterTypes.length > 0) { return clazz.getConstructor(parameterTypes); } else { return clazz.getConstructor(); } catch (Exception exp) { return null; ... |