https://kotlinlang.org logo
#library-development
Title
# library-development
d

Drew Hamilton

05/06/2020, 10:52 AM
Is converting a sealed class to an interface a binary compatible change? I’m leaning toward “effectively yes other than some reflection problems” but not confident at all.
a

altavir

05/06/2020, 1:45 PM
No it is not. It should not break compatibility for descendants, but it surely will for the class itself.
d

Drew Hamilton

05/06/2020, 1:50 PM
In what sense? Can you give an example of a call that would work for the sealed class and not work for the interface (when the consumer is not recompiled)?
a

altavir

05/06/2020, 3:14 PM
Their byte-code representation is different. There is surely difference on the reflection level. The general usage should be the same
z

Zach Klippenstein (he/him) [MOD]

05/06/2020, 4:08 PM
I think if you're sealed class has any concrete methods, the bytecode to call them would be incompatible, especially if you don't use
@JvmDefaults
on your interface (but maybe even then).
d

Drew Hamilton

05/06/2020, 7:50 PM
Good point on the concrete functions, the case I was thinking of happens to have none.
e

elizarov

05/09/2020, 9:01 PM
It is
invokevirtual
vs
invokeinterface
at the bytecode level
2
d

Drew Hamilton

05/10/2020, 2:20 PM
Ahhh never knew those were different! Thanks!
4 Views