`this::class` is available, but `super::class` - n...
# announcements
u
this::class
is available, but
super::class
- not. Need this.
k
super
references any super type, that is the class and interfaces. It is not specific to a class, making it impossible to provide such a function. If you want to get hold of all super types, use
this::class.supertypes
.
Also
this::class.superclasses
if you want the classes only.
m
There is also
this::class.allSuperclasses
u
@kralli @marstran thank you, guys. But how can we get just direct parent class? I use Kotlin/JS, not JVM.
m
I don't think you can. What do you need that for?
Also, let's say you have
class A : A1, A2, A3
. Which class object would you expect to get?
u
@marstran I interest only in class. Only one class can apear in a supertype list. So in your example I expect
Any
But in such example
class A : A1, A2(), A3
I expect
A2
this::class.supertypes
is marked as supported for JS in the documentation. But in fact compiler produce error
Unsupported [This reflection API is not supported yet in JavaScript]
k
this::class.superclasses
is marked as supported for JVM only,
this::class.supertypes
however should be supported
m
Anyway, this kind of feels like an XY problem. What exactly are you trying to solve? If your application design requires you to find the direct superclass of your object, you must be doing something wrong.
1
1
u
@marstran easy to say "you must be doing something wrong". It can be said about reflection API at all. My application design requires to interact with external JS lib. To make my code work I need to write some boilerplate (because Kotlin/JS do it bad). Every time I extend any TypeScript class, I need to call some function with parameter of parent class (because Kotlin/JS can't inherit TypeScript class correctly). Of cause I do
A2::class.js
. I just wanted to bring this duplicate code to a separate function.
m
Sorry, didn't mean to be condescending. What I meant was that your actual problem is extending a TypeScript class, not getting the class object of the direct superclass. You might get better answers by asking that instead, and giving the kotlin.reflections code as an example of what you have tried. 🙂