Java Utililty Methods Reflection Constructor Get

List of utility methods to do Reflection Constructor Get

  1. HOME
  2. Java
  3. R
  4. Reflection Constructor Get

Description

The list of methods to do Reflection Constructor Get are organized into topic(s).

Method

Constructor getConstructor(Class clazz, Class... argTypes)
get Constructor
try {
 return clazz.getConstructor(argTypes);
} catch (NoSuchMethodException e) {
 throw new IllegalStateException(e);
Constructor getConstructor(Class clazz, Class[] argTypes)
get Constructor
if (clazz == null || argTypes == null) {
 throw new IllegalArgumentException();
try {
 return clazz.getConstructor(argTypes);
} catch (NoSuchMethodException e) {
 return null;
Constructor getConstructor(Class clazz, Class[] parametersTypes)
Gets the constructor with specified parameter types.
return clazz.getDeclaredConstructor(parametersTypes);
Constructor getConstructor(Class clazz, Class[] paramTypes)
get Constructor
for (Constructor c : clazz.getConstructors()) {
 if (isAssignable(c.getParameterTypes(), paramTypes))
 return c;
return clazz.getConstructor(paramTypes);
Constructor getConstructor(Class clazz, Class[] paramTypes)
get Constructor
return getConstructor(clazz, paramTypes, false);
Constructor getConstructor(Class cls, Class[] args)
get Constructor
return getConstructor(cls, args, null);
Constructor getConstructor(Class clz, Class expectedTypes[])
get Constructor
Constructor constructor = null;
try {
 Constructor constructors[] = clz.getConstructors();
 for (int i = 0; i < constructors.length; i++) {
 Constructor creator = constructors[i];
 if (isAssignable(expectedTypes, creator.getParameterTypes()))
 if (constructor == null)
 constructor = creator;
...
Constructor getConstructor(Class type, Class[] argTypes)
Returns a Constructor for the given method signature, or null if no such Constructor can be found.
if (null == type || null == argTypes) {
 throw new NullPointerException();
Constructor ctor = null;
try {
 ctor = type.getConstructor(argTypes);
} catch (Exception e) {
 ctor = null;
...
Constructor getConstructor(Class c, Class[] args)
Answer the constructor of the class c which takes arguments of the type(s) in args, or null if there isn't one.
try {
 return c.getConstructor(args);
} catch (NoSuchMethodException e) {
 return null;
Constructor getConstructor(Class clazz, boolean declared, Class... args)
get Constructor
try {
 Constructor<?> constructor = null;
 if (declared) {
 constructor = clazz.getDeclaredConstructor(args);
 constructor.setAccessible(true);
 } else
 constructor = clazz.getConstructor(args);
 return constructor;
...


AltStyle によって変換されたページ (->オリジナル) /