# UsesReflectionToAccessField

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/UsesReflectionToAccessField.kt+class:androidx.annotation.keep.UsesReflectionToAccessField) Added in [1.0.0-alpha01](https://developer.android.com/jetpack/androidx/releases/annotation-keep#1.0.0-alpha01)

*** ** * ** ***


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

<br />

*** ** * ** ***

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

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

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

## Summary

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?>` | `https://developer.android.com/reference/androidx/annotation/keep/UsesReflectionToAccessField#getClassConstant()()` Class containing the field accessed by reflection. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/annotation/keep/UsesReflectionToAccessField#getClassName()()` Class name (or class name pattern) containing the field accessed by reflection. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/annotation/keep/UsesReflectionToAccessField#getFieldName()()` Name (or name pattern) of field accessed by reflection. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?>` | `https://developer.android.com/reference/androidx/annotation/keep/UsesReflectionToAccessField#getFieldType()()` Type of field accessed by reflection. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/annotation/keep/UsesReflectionToAccessField#getFieldTypeName()()` Type (or type pattern) of field accessed by reflection. |

## Public methods

### getClassConstant

```
public final @NonNull KClass<@NonNull ?> getClassConstant()
```

Class containing the field accessed by reflection.

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

### getClassName

```
public final @NonNull String getClassName()
```

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

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

### getFieldName

```
public final @NonNull String getFieldName()
```

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

### getFieldType

```
public final @NonNull KClass<@NonNull ?> getFieldType()
```

Type of field accessed by reflection.

Ignored if not specified.

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

### getFieldTypeName

```
public final @NonNull String getFieldTypeName()
```

Type (or type pattern) of field accessed by reflection.

Ignored if not specified.

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