# RestrictTo

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

*** ** * ** ***

Common/AllAndroid/JVM
- Cmn

  ```
  @MustBeDocumented
  @Retention(value = AnnotationRetention.BINARY)
  @Target(allowedTargets = [AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FIELD, AnnotationTarget.FILE])
  annotation RestrictTo
  ```
- android

  ```
  @MustBeDocumented
  @Retention(value = AnnotationRetention.BINARY)
  @Target(allowedTargets = [AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FIELD, AnnotationTarget.FILE])
  @Target(value = [ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE])
  annotation RestrictTo
  ```

*** ** * ** ***

Denotes that the annotated element should only be accessed from within a specific scope (as defined by `https://developer.android.com/reference/kotlin/androidx/annotation/RestrictTo.Scope`).

Example of restricting usage within a library (based on Gradle group ID):

```kotlin
@RestrictTo(GROUP_ID)
public void resetPaddingToInitialValues() { ...
```

Example of restricting usage to tests:

```kotlin
@RestrictTo(Scope.TESTS)
public abstract int getUserId();
```

Example of restricting usage to subclasses:

```kotlin
@RestrictTo(Scope.SUBCLASSES)
public void onDrawForeground(Canvas canvas) { ...
```

Note, this enforcement is done via Android Lint RestrictedApi check. This check is automatically run for Android projects and can be optionally enabled on JVM projects using the com.android.lint Gradle plugin.

## Summary

| ### Nested types |
|---|
| `enum https://developer.android.com/reference/kotlin/androidx/annotation/RestrictTo.Scope : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-enum/index.html<https://developer.android.com/reference/kotlin/androidx/annotation/RestrictTo.Scope>` |

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/annotation/RestrictTo#RestrictTo(kotlin.Array)(vararg value: https://developer.android.com/reference/kotlin/androidx/annotation/RestrictTo.Scope)` | Cmn android |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/annotation/RestrictTo.Scope>` | `https://developer.android.com/reference/kotlin/androidx/annotation/RestrictTo#value()` The scope(s) to which usage should be restricted. | Cmn android |

## Public constructors

### RestrictTo

Cmn android Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/annotation#1.10.0)

```
RestrictTo(vararg value: RestrictTo.Scope)
```

## Public properties

### value

Cmn android

```
val value: Array<RestrictTo.Scope>
```

The scope(s) to which usage should be restricted.