
org.objenesis.instantiator.basic.ConstructorInstantiator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockito-all Show documentation
Show all versions of mockito-all Show documentation
Mock objects library for java, modified to allow cache disabling
The newest version!
package org.objenesis.instantiator.basic;
import java.lang.reflect.Constructor;
import org.objenesis.ObjenesisException;
import org.objenesis.instantiator.ObjectInstantiator;
/**
* Instantiates a class by grabbing the no args constructor and calling Constructor.newInstance().
* This can deal with default public constructors, but that's about it.
*
* @see ObjectInstantiator
*/
public class ConstructorInstantiator implements ObjectInstantiator {
protected Constructor constructor;
public ConstructorInstantiator(Class type) {
try {
constructor = type.getDeclaredConstructor((Class[]) null);
}
catch(Exception e) {
throw new ObjenesisException(e);
}
}
public Object newInstance() {
try {
return constructor.newInstance((Object[]) null);
}
catch(Exception e) {
throw new ObjenesisException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy