@Override
public ObjectConstructor newConstructor(final Class<?> cls) {
for (Class<?> cls0 = cls; cls != Object.class; cls0 = cls0.getSuperclass()) {
try {
Constructor<?> ctor = cls0.getDeclaredConstructor();
final ConstructorAccessor constructorAccessor = (cls0 == cls)
? newConstructorAccessor(ctor)
: newConstructorAccessor(ctor, cls);
return new ObjectConstructor() {
@Override
public Object newInstance() {
try {
return constructorAccessor.newInstance(null);
} catch (InstantiationException | InvocationTargetException e) {
throw new Sql2oException("Could not create a new instance of class " + cls, e);
}
}
};