Historically, we have multiple interfaces that are not designed for external implementation, , but are not sealed for various reasons (including historical ones):
Job should not be extended externally
Deferred and CompletableDeferred should not be extended externally
Channelprobably should not be extended externally
It is not mentioned in the documentation, and it's impossible to fulfil the select's contract with a hand-rolled implementation
Yet it is possible to implement it with a delegation, potentially closing the possibility of adding new abstract members to the interface
Flow, SharedFlow, and StateFlow are unstable/experimental for inheritance
CloseableCoroutineDispatcher is unstable for inheritance
CancellableContinuation is an interface not ready to be extended
For "prohibited to implement" interfaces we can introduce the new annotation with a warning (or maybe even an error) and, in the next major release, make the annotation internal itself, so it would be much harder to opt-in
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-subclass-opt-in-required/
Historically, we have multiple interfaces that are not designed for external implementation, , but are not
sealed
for various reasons (including historical ones):Job
should not be extended externallyDeferred
andCompletableDeferred
should not be extended externallyChannel
probably should not be extended externallyYet it is possible to implement it with a delegation, potentially closing the possibility of adding new abstract members to the interface
Flow
,SharedFlow
, andStateFlow
are unstable/experimental for inheritanceCloseableCoroutineDispatcher
is unstable for inheritanceCancellableContinuation
is an interface not ready to be extendedIt would be nice to adopt the
SubclassOptInRequired
(available from 1.9.0) in the library to provide explicit programmatic warnings/errors and to prevent issues like https://github.com/Kotlin/kotlinx.coroutines/issues/3729For "prohibited to implement" interfaces we can introduce the new annotation with a warning (or maybe even an error) and, in the next major release, make the annotation
internal
itself, so it would be much harder to opt-in