Annotation Interface RequiresOptIn
Marker annotations must have runtime retention and apply to the following
targets (or a subset thereof):
ElementType.ANNOTATION_TYPEElementType.CONSTRUCTORElementType.FIELDElementType.METHODElementType.MODULEElementType.PACKAGEElementType.RECORD_COMPONENTElementType.TYPE
Declarations annotated with the marker annotation require an explicit opt-in either by OptIn, or by having
the same opt-in requirements (for example) by being annotated with the same marker annotation.
Opt-in requirements are contagious. Use-sites of a declaration that requires an explicit opt-in, must explicitly
opt in into the requirement (via OptIn) or propagate the requirement by also using the marker annotation.
Users may utilize this property to exempt certain APIs from the libraries default API stability rules. If, for
example, an Experimental annotation marker is used to denote potentially unstable APIs, a removal of a
declaration marked as experimental would only break use-sites that explicitly opted into using the experimental API.
A declared type requires opt-in if its declaration or any enclosing declaration is annotated with a marker annotation. Enclosing declarations may include (but are not limited to) outer classes, interfaces, packages, and modules. A type that mentions a type that requires an explicit opt-in in its signature also requires an explicit opt-in.
@UnstableApi
public class Unstable {
void memberMethod() {}
static class NestedClass {
void nestedMethod() {}
}
}
In this example, any use of `Unstable`, `NestedClass`, or their member methods require an explicit opt-in.
- Since:
- 0.1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumLevels used for identifying the severity of using an opt-in API without explicitly declaring it. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionReturns the severity of the diagnostic that should be reported on usages which did not explicitly opted into the API either by usingOptInor by being annotated with the corresponding marker annotation.Returns the message to be reported on usages of API without an explicit opt-in, or the empty string for a generated default message.
-
Element Details
-
message
String messageReturns the message to be reported on usages of API without an explicit opt-in, or the empty string for a generated default message.- Returns:
- the message to be reported on usages of API without an explicit opt-in, or the empty string for a generated default message
- Since:
- 0.1.0
- Default:
""
-
level
RequiresOptIn.Level levelReturns the severity of the diagnostic that should be reported on usages which did not explicitly opted into the API either by usingOptInor by being annotated with the corresponding marker annotation.- Returns:
- the severity of the diagnostic that should be reported on usages which did not explicitly opted into
the API either by using
OptInor by being annotated with the corresponding marker annotation - Since:
- 0.1.0
- Default:
ERROR
-