In swift, we can confirm to any protocol / interface using extensions. Can we add interface conformance to certain class using extension in Kotlin?
g
gildor
11/07/2022, 8:02 AM
No, it’s not possible and probably will never be supported, because it wouldn’t work on JVM without some huge hacks and will anyway break compatibility with Java
r
Rohan Sanap
11/07/2022, 8:02 AM
ok, thanks.
s
Stephan Schroeder
11/07/2022, 8:26 AM
sounds like traits in Rust!? I enjoy figuring out the difference between those and the interfaces I'm used to Java/Kotlin (apart from the obvious fact that interface extension can only happen while the extending class itselft is written. E.g. implementing traits not for a specific struct but for other traits.)
But yeah, in regards to the original question: that doesn't work in Kotlin.