RequiresOptIn

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 OptIn or by being annotated with that marker themselves, effectively causing further propagation of that opt-in aspect.

Example:

`
// Library code
@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
}
`
*

Summary

Nested types

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 fields

final @NonNull RequiresOptIn.Level

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

Public constructors

Public fields

level

@NonNull
public final @NonNull RequiresOptIn.Level level

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

Public constructors

RequiresOptIn

public final RequiresOptIn(@NonNull RequiresOptIn.Level level)