how can I use kotlin-reflect to get all subclasses...
# announcements
p
how can I use kotlin-reflect to get all subclasses of an abstract base class? the base class is NOT sealed
m
Using solely
kotlin-reflect
? There is none. On JVM you’d have to use Java API to scan all classes in all packages in all classpaths and then check if they’re a subclass. Neither performant nor too reliable.
p
Ok well too bad - thanks @Marc Knaup
t
that, I think, is exactly the point of sealed classes and why the compiler can check exhaustive `when`s for instance. if it was easy to do without too much overhead there would not be a need for
sealed
😄
p
i love sealed classes … only issue is the files tend to get really large
even when stripping off as much as you can from the sealed classes and relocating logic elsewhere
m
@Peter Ertl for Kotlin 1.5. they’re working on allowing you to have subclasses of
sealed
classes in different files of the same project & package.
p
that will be the nirvana of coding 🙂
jetbrains +1
can’t wait for it 🙂
m
We also get
sealed interface
:)
p
yeah, even more goodness
they are so kind to release us from the burden of java code which feels so 1990
m
Exactly. Just the interoperability with Java prevents some features from reaching their maximum potential.
p
I am really amazed on how close to “real” pattern matching (like in haskell, scala, etc.) you can come with sealed classes.
kotlin is just so “wow”
I converted a current project in a company I am freelancing for from java to kotlin
it’s just a 180 degree turn from boredom to fun
1
I always hoped that scala will make it somehow but they always denied java so interop is a PITA and scala 3 comes too late with too little… so kotlin made life meaningful again (and I can do functional stuff easier without looking for a haskell project) … thanks to all you guys (I assume you are part of the jetbrains team)
m
I am not. Just using Kotlin way too much.
And building way too many libraries along the way 😄
👍 1
p
ok … anyway … you can’t use too much of kotlin imho
t
to be fair java is aware and trying to overcome some limitation. I am not much interested in going deeper, but project amber is introducing sealed classes, records (akin to data classes) and pattern matching (more powerful than what you can currently do in kotlin)
I guess they got scared of the traction kotlin got
p
true, but they will always suffer from their legacy and it’s getting harder and harder to implement cool stuff without dropping some cruft
I guess kotlin scares the hell of of them
t
problem is, for java, this feature will be available on Android in ~100 years
m
I hope Amber moves faster than Project Valhalla which started 6 years ago and still isn’t done 😅
p
kotlin could always decide to drop jvm support and compile to native or their own jvm implementation (though I don’t expect them to)
they always have an option but oracle does not
m
They already have their own VM for Native - more or less. Over time JVM could easily become obsolete for Kotlin.
p
full ack
t
records are definitely available already, so I guess everything
delivered
is usable, provided a recent enough jvm. the delivery every 6 months rather than by feature makes things so much faster
as an impression. the idea of agile
1081 Views