# RequiresOptIn

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

*** ** * ** ***

Common/AllAndroid/JVM
- android

  ```
  @Retention(value = AnnotationRetention.BINARY)
  @Target(allowedTargets = [AnnotationTarget.ANNOTATION_CLASS])
  annotation RequiresOptIn
  ```

*** ** * ** ***

Denotes that the annotated element is a marker of an opt-in API.

Any declaration annotated with this marker is considered part of an unstable or otherwise non-standard API surface and its call sites should accept the opt-in aspect of it either by using `https://developer.android.com/reference/kotlin/androidx/annotation/OptIn` or by being annotated with that marker themselves, effectively causing further propagation of that opt-in aspect.

```kotlin
// Marker definition

@Retention(CLASS)
@Target({TYPE, METHOD, CONSTRUCTOR, FIELD, PACKAGE})
@RequiresOptIn(level = Level.ERROR)
public @interface ExperimentalDateTime {}

@ExperimentalDateTime
public class DateProvider {
  // ...
}

// Client code

int getYear() {
  DateProvider provider; // Error: DateProvider is experimental
  // ...
}

@ExperimentalDateTime
Date getDate() {
  DateProvider provider; // OK: the function is marked as experimental
  // ...
}

void displayDate() {
  System.out.println(getDate()); // Error: getDate() is experimental, acceptance is required
}
```

To configure project-wide opt-in, specify the `opt-in` option value in `lint.xml` as a comma-delimited list of opted-in annotations:

```kotlin
<lint>
  <issue id="$issueId">
    <option name="opt-in" value="com.foo.ExperimentalBarAnnotation" />
  </issue>
</lint>
```

## Summary

| ### Nested types |
|---|
| `enum https://developer.android.com/reference/kotlin/androidx/annotation/RequiresOptIn.Level : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-enum/index.html<https://developer.android.com/reference/kotlin/androidx/annotation/RequiresOptIn.Level>` Severity of the diagnostic that should be reported on usages of opt-in API which did not explicitly accept the opt-in aspect of that API either by: |

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/annotation/RequiresOptIn#RequiresOptIn(androidx.annotation.RequiresOptIn.Level,kotlin.String)(level: https://developer.android.com/reference/kotlin/androidx/annotation/RequiresOptIn.Level, message: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` | android |

| ### Public properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/annotation/RequiresOptIn.Level` | `https://developer.android.com/reference/kotlin/androidx/annotation/RequiresOptIn#level()` Defines the reporting level for incorrect usages of this opt-in API. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/annotation/RequiresOptIn#message()` Message to be reported on usages of API without an explicit opt-in, or empty string for the default message. | android |

## Public constructors

### RequiresOptIn

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

```
RequiresOptIn(level: RequiresOptIn.Level = Level.ERROR, message: String = "")
```

## Public properties

### level

android

```
val level: RequiresOptIn.Level
```

Defines the reporting level for incorrect usages of this opt-in API.

### message

android

```
val message: String
```

Message to be reported on usages of API without an explicit opt-in, or empty string for the default message. The default message is: "This declaration is experimental and its usage should be marked with 'Marker' or '@OptIn(Marker::class)'", where Marker is the opt-in requirement marker.