# ConstructorInvocation

Artifact: [androidx.test.espresso:espresso-core](https://developer.android.com/jetpack/androidx/releases/test-espresso) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/remote/ConstructorInvocation.java+class:androidx.test.espresso.remote.ConstructorInvocation)

*** ** * ** ***

<br />

```
public final class ConstructorInvocation
```

<br />

*** ** * ** ***

Reflectively invokes the constructor of a declared class.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/test/espresso/remote/ConstructorInvocation#ConstructorInvocation(java.lang.Class<?>,java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.Class<?>...)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> clazz, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Class.html<https://developer.android.com/reference/java/lang/annotation/Annotation.html> annotationClass, @https://developer.android.com/reference/androidx/annotation/Nullable Class[] parameterTypes )` Creates a new `https://developer.android.com/reference/androidx/test/espresso/remote/ConstructorInvocation`. |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/test/espresso/remote/ConstructorInvocation#invokeConstructor(java.lang.Object...)(Object[] constructorParams)` Invokes the target constructor with the provided constructor parameters |

## Public constructors

### ConstructorInvocation

```
public ConstructorInvocation(
    @NonNull Class<@NonNull ?> clazz,
    @Nullable Class<Annotation> annotationClass,
    @Nullable Class[] parameterTypes
)
```

Creates a new `https://developer.android.com/reference/androidx/test/espresso/remote/ConstructorInvocation`.

Constructor lookup is either done using an annotation by passing the `annotationClass` as a parameter or through `parameterTypes` lookup. This class will attempt to lookup a constructor by first looking for a constructor annotated with `annotationClass`. If no constructors are found it will fallback and try to use `parameterTypes`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> clazz` | the declared class to create the instance off |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Class.html<https://developer.android.com/reference/java/lang/annotation/Annotation.html> annotationClass` | the annotation class to lookup the constructor |
| `@https://developer.android.com/reference/androidx/annotation/Nullable Class[] parameterTypes` | array of parameter types to lookup a constructor on the declared class. The declared order of parameter types must match the order of the constructor parameters passed into `https://developer.android.com/reference/androidx/test/espresso/remote/ConstructorInvocation#invokeConstructor(java.lang.Object...)`. |

## Public methods

### invokeConstructor

```
public Object invokeConstructor(Object[] constructorParams)
```

Invokes the target constructor with the provided constructor parameters

| Parameters |
|---|---|
| `Object[] constructorParams` | array of objects to be passed as arguments to the constructor |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/Object.html` | a new instance of the declared class |