In Kotlin 1.4.30, when I type
open interface I
the Kotlin compiler warns me that modifier 'open' is redundant for 'interface'
. This makes complete sense: Of course interfaces are open, otherwise they would be useless.
However, the reflection library seems to contradict this:
interface I
println(I::class.isOpen) // prints 'false'
How does this make sense? The KDoc of isOpen
is very brief:
true
if this class is open.
What exactly is the definition of "open" in Kotlin? I thought it meant "open to the possibility of being sub-typed by classes outside this file".
The methods isFinal
, isOpen
, isAbstract
, isSealed
were designed such that only one of them returns true for all KClass
instances.
Source: this comment in KT-19850.
Since interfaces are abstract, I::class.isAbstract == true
. Combined with the above design goal, I::class.isOpen == false
results.
Please upvote KT-19850 to help getting this surprising behavior fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With