List of utility methods to do Reflection Constructor Get
Constructor> | getConstructor(final Class> clazz, final Class>[] paramTypes) Returns the constructor with the given parameter types, or null if not found.
for (final Constructor<?> candidate : clazz.getConstructors()) { if (Arrays.equals(paramTypes, candidate.getParameterTypes())) { return candidate; return null; |
Constructor | getConstructor(final Class get Constructor final Constructor<E> constructor; final String classID = valueClass.getName(); try { constructor = valueClass.getDeclaredConstructor(parameter); } catch (final NoSuchMethodException e) { throw new IllegalArgumentException(classID + " does not have a constructor " + valueClass.getSimpleName() + '(' + getName(parameter) + ')', e); constructor.setAccessible(true); return constructor; |
Constructor | getConstructor(final Class Get a constructor by args. final Constructor<T> result = clazz.getDeclaredConstructor(parametertypes); return result; |
Constructor | getConstructor(final Class Returns the public constructor of the specified class or null if no such constructor try { return clazz.getConstructor(parameterTypes); } catch (final Exception e) { return null; |
Constructor | getConstructor(final Class get Constructor final Constructor<T> constructor = getStrictConstructor(clazz, constructorArgs); return constructor == null ? findCompatibleConstructor(clazz, constructorArgs) : constructor; |
Constructor | getConstructor(final Class Returns a constructor that contains objs as arguments. Constructor<T> ret = null; for (final Constructor<?> classConstructor : clazz.getDeclaredConstructors()) { if (isMatchingConstructor(classConstructor, objs)) { if (ret != null) { throw new IllegalArgumentException( "Ambiguity in the constructors for " + clazz.getName() + "."); ret = (Constructor<T>) classConstructor; ... |
Constructor | getConstructor(final Class Get a constructor for a class and put the result in cache, to increase speed for the next call. final int hashCode = instantiableClass.hashCode() ^ Arrays.hashCode(classes); if (constructorCache.containsKey(hashCode)) { return (Constructor<T>) constructorCache.get(hashCode); } else { if (!constructorsCache.containsKey(instantiableClass)) { constructorsCache.put(instantiableClass, instantiableClass.getDeclaredConstructors()); boolean mismatch; ... |
Constructor extends T> | getConstructor(String className, Class>... argClasses) get Constructor return ((Class<? extends T>) Class.forName(className)).getConstructor(argClasses); |
Constructor> | getConstructor(String cls_name, Class>[] param_cls) get Constructor try { Class<?> c = Class.forName(cls_name); return c.getConstructor(param_cls); } catch (Exception e) { return null; |
Constructor | getConstructor(String string, Class... types) get Constructor try { Class clazz = Class.forName(string); Constructor constructor = clazz.getDeclaredConstructor(types); constructor.setAccessible(true); return constructor; } catch (Exception ex) { return null; ... |