Example usage for org.apache.commons.lang3.reflect ConstructorUtils invokeExactConstructor

List of usage examples for org.apache.commons.lang3.reflect ConstructorUtils invokeExactConstructor

Introduction

In this page you can find the example usage for org.apache.commons.lang3.reflect ConstructorUtils invokeExactConstructor.

Prototype

public static <T> T invokeExactConstructor(final Class<T> cls, Object[] args, Class<?>[] parameterTypes)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
        InstantiationException 

Source Link

Document

Returns a new instance of the specified class choosing the right constructor from the list of parameter types.

This locates and calls a constructor.

Usage

From source file:org.gerzog.spock.injectmock.internal.accessors.ConstructorAccessor.java

@Override
public Object apply(final Object target, final String name, final Object value) {
    try {//w  w  w  . j  av  a  2 s.c  o m
        final Object[] values = (Object[]) value;
        final Class<?>[] types = InjectMocksUtils.toClassArray(values, Object::getClass);
        return ConstructorUtils.invokeExactConstructor((Class<?>) target, values, types);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException
            | InstantiationException e) {
        throw new InvalidSpecException(
                "Cannot create <" + target + "> object by constructor args <" + value + ">", e);
    }
}