# UsesReflectionToAccessMethod

Artifact: [androidx.annotation.keep:keep](https://developer.android.com/jetpack/androidx/releases/annotation-keep) [View Source](https://cs.android.com/search?q=file:androidx/annotation/keep/UsesReflectionToAccessMethod.kt+class:androidx.annotation.keep.UsesReflectionToAccessMethod) Added in [1.0.0-alpha01](https://developer.android.com/jetpack/androidx/releases/annotation-keep#1.0.0-alpha01)

*** ** * ** ***

Common/All
- Cmn

  ```
  @Retention(value = AnnotationRetention.BINARY)
  @Repeatable
  @Target(allowedTargets = [AnnotationTarget.CLASS, AnnotationTarget.FIELD, AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR])
  annotation UsesReflectionToAccessMethod
  ```

*** ** * ** ***

The annotated code uses reflection to indirectly access a method of the specified class/interface, or its subclasses / interface implementers.

This annotation indicates to optimizers or shrinkers that the target method should be preserved if the annotated code is reachable in the final application build.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToConstruct` |   |
| `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessField` |   |

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#UsesReflectionToAccessMethod(kotlin.reflect.KClass,kotlin.String,kotlin.String,kotlin.Array,kotlin.Array,kotlin.reflect.KClass,kotlin.String)( classConstant: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<*>, className: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, methodName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, parameterTypes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<*>>, parameterTypeNames: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>, returnType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<*>, returnTypeName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html )` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<*>` | `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#classConstant()` Class containing the method accessed by reflection. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#className()` Class name (or class name pattern) containing the method accessed by reflection. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#methodName()` Name (or name pattern) of method accessed by reflection. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#parameterTypeNames()` Defines which method to keep by specifying set of parameter classes passed. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<*>>` | `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#parameterTypes()` Defines which method to keep by specifying set of parameter classes passed. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<*>` | `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#returnType()` Return type of the method accessed by reflection. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#returnTypeName()` Return type (or type pattern) of the method accessed by reflection. | Cmn |

## Public constructors

### UsesReflectionToAccessMethod

Cmn

```
UsesReflectionToAccessMethod(
    classConstant: KClass<*> = Unspecified::class,
    className: String = "",
    methodName: String,
    parameterTypes: Array<KClass<*>> = [Unspecified::class],
    parameterTypeNames: Array<String> = [""],
    returnType: KClass<*> = Unspecified::class,
    returnTypeName: String = ""
)
```

## Public properties

### classConstant

Cmn

```
val classConstant: KClass<*>
```

Class containing the method accessed by reflection.

Mutually exclusive with `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#(kotlin.reflect.KClass,kotlin.String,kotlin.String,kotlin.Array,kotlin.Array,kotlin.reflect.KClass,kotlin.String)`.

### className

Cmn

```
val className: String
```

Class name (or class name pattern) containing the method accessed by reflection.

Mutually exclusive with `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#(kotlin.reflect.KClass,kotlin.String,kotlin.String,kotlin.Array,kotlin.Array,kotlin.reflect.KClass,kotlin.String)`.

### methodName

Cmn

```
val methodName: String
```

Name (or name pattern) of method accessed by reflection.

### parameterTypeNames

Cmn

```
val parameterTypeNames: Array<String>
```

Defines which method to keep by specifying set of parameter classes passed.

If neither `parameterTypes` nor `parameterTypeNames` is specified then methods with all parameter lists are kept.

Mutually exclusive with `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#(kotlin.reflect.KClass,kotlin.String,kotlin.String,kotlin.Array,kotlin.Array,kotlin.reflect.KClass,kotlin.String)`.

### parameterTypes

Cmn

```
val parameterTypes: Array<KClass<*>>
```

Defines which method to keep by specifying set of parameter classes passed.

If neither `parameterTypes` nor `parameterTypeNames` is specified then methods with all parameter lists are kept.

Mutually exclusive with `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#(kotlin.reflect.KClass,kotlin.String,kotlin.String,kotlin.Array,kotlin.Array,kotlin.reflect.KClass,kotlin.String)`.

### returnType

Cmn

```
val returnType: KClass<*>
```

Return type of the method accessed by reflection.

Ignored if not specified.

Mutually exclusive with `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#(kotlin.reflect.KClass,kotlin.String,kotlin.String,kotlin.Array,kotlin.Array,kotlin.reflect.KClass,kotlin.String)`.

### returnTypeName

Cmn

```
val returnTypeName: String
```

Return type (or type pattern) of the method accessed by reflection.

Ignored if not specified.

Mutually exclusive with `https://developer.android.com/reference/kotlin/androidx/annotation/keep/UsesReflectionToAccessMethod#(kotlin.reflect.KClass,kotlin.String,kotlin.String,kotlin.Array,kotlin.Array,kotlin.reflect.KClass,kotlin.String)`.