I want to bring kotlin support to a java library w...
# getting-started
n
I want to bring kotlin support to a java library without adding kotlin to it. What I want is to make a sealed class. Is there any kind of meta data or naming conventions I can use to make my classes work as a sealed class when consumed by kotlin?
nope 1
j
sealed classes
are a Kotlin feature, so you can't at the moment. I think Kotlin might soon support the new "permitted subsclasses" JVM feature that was added in Java 15: https://youtrack.jetbrains.com/issue/KT-41214 But at the moment I don't believe it's possible to do what you want
n
How does the compiler know though after the kotlin class is converted to bytecode?? There has got to be some kind of metadata or naming convention. When I reverse compile a sealed class I see the java structure needed. But the metadata is byte strings not sure how they are generated, and there may be a naming convention as well.
e
Kotlin serializes extra info that cannot be expressed in bytecode to both the
@kotlin.Metadata
annotation as well as a
.kotlin_module*
file
💯 1
the kotlinx.metadata.jvm library can read and write those, but it's definitely not intended to be a public interface
👍 1
in practice the metadata is partly a shared constant pool and partly a serialized protobuf
it's not something you can write by hand and add to a Java class
n
Interesting… I think I follow your github profile, your looks familiar. I think you had some great advent of code solutions 🙂
🙏 1