![JAR search and dependency download from the Maven repository](/logo.png)
refutils.util.ConstructorHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of reflection-utils Show documentation
Show all versions of reflection-utils Show documentation
A utility library to handle Java reflection with ease
package refutils.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
* Utility class to handle constructors.
*
* @param The type to instantiate
* @author exbjek
*/
public final class ConstructorHelper {
private final Class clazz;
public ConstructorHelper(final Class clazz) {
this.clazz = clazz;
}
/**
* Instantiate private empty constructor.
*
* @return the instance
* @throws NoSuchMethodException if a matching method is not found.
* @throws IllegalAccessException should never be thrown since the constructor is made accessible
* @throws InvocationTargetException if the underlying constructor throws an exception.
* @throws InstantiationException if the class that declares the underlying constructor represents an abstract class.
*/
public T instantiatePrivate() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
Constructor constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
return constructor.newInstance();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy