You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`SubclassOptInRequired` is not propagated to inner and nested classes. Opt-in is required only when inheriting from a class on which the `SubclassOptInRequired` annotation has been explicitly specified.
114
+
115
+
```kotlin
116
+
@RequiresOptIn
117
+
annotationclassAPI
118
+
119
+
@SubclassOptInRequired(API::class)
120
+
openclassA {
121
+
openclassB
122
+
}
123
+
124
+
classC1: A() // opt-in required
125
+
classC2 : A.B() // no opt-in required
126
+
```
127
+
128
+
### Interaction with Java code
129
+
130
+
Since the Kotlin compiler can't report errors or warnings in Java code, adding the opt-in is not required for the Java classes or interfaces.
131
+
132
+
```kotlin
133
+
// a.kt
134
+
@RequiresOptIn
135
+
annotationclassAPI
136
+
137
+
@SubclassOptInRequired(API::class)
138
+
openclassKotlinCl
139
+
140
+
// b.java
141
+
publicclassFoo extends KotlinCl {} // no opt-in required
142
+
143
+
```
144
+
Also, Java code suppresses the propagation of opt-in requirements. Therefore, if a class in Kotlin inherits from the Java class `Foo`, opt-in is not required for the inheritance.
145
+
146
+
```kotlin
147
+
// c.kt
148
+
classBar: Foo() //no opt-in required
149
+
```
150
+
151
+
To propagate experimentation through Java code, it is required to explicitly use the `SubclassOptInRequired` annotation in Java code.
152
+
153
+
```kotlin
154
+
// a.kt
155
+
@RequiresOptIn
156
+
annotationclassAPI
157
+
158
+
@SubclassOptInRequired(API::class)
159
+
openclassKotlinCl
160
+
161
+
// b.java
162
+
@SubclassOptInRequired(API::class)
163
+
publicclassFoo extends KotlinCl {}
164
+
165
+
// c.kt
166
+
classBar: Foo() // opt-in required
167
+
```
110
168
111
169
### Restrictions and limitations
112
170
@@ -128,6 +186,6 @@ opting-in into extension and opting-in into overall uses.
128
186
129
187
### Status and timeline
130
188
131
-
The feature is available since Kotlin 1.8.0 as experimental (it itself requires an opt-in
189
+
The feature is available since Kotlin 2.0.0 as experimental (it itself requires an opt-in
132
190
into `ExperimentalSubclassOptIn`)
133
-
and is expected to be promoted to stable in Kotlin 1.9.0.
191
+
and is expected to be promoted to stable in Kotlin 2.1.0.
0 commit comments