James Whitehead
08/24/2021, 11:36 AMisInterface
? I see we have isAbstract
, isOpen
, etc, but I haven't found anything for interface.
2. Follow up question; is MyClass::class.java.interfaces
the recommended way to get the interfaces implemented by a given class?Ivan Pavlov
08/24/2021, 12:05 PMsupertypes
or allSupertypes
and process them somehow I guessRob Elliot
08/24/2021, 1:58 PMval KClass<*>.isInterface get() = constructors.isEmpty()
should work.Ivan Pavlov
08/24/2021, 2:01 PMPlease note that the constructors counting solution might not be very precise for general purpose use. For example, Kotlin package facade classes do not have any constructors either, but they are not interfaces (UPD: and their constructors cannot even be reflected with, just as those of anonymous classes,kotlin-reflect
and maybe more).KFunction
Rob Elliot
08/24/2021, 2:03 PMJames Whitehead
08/24/2021, 11:06 PMAny
KClass.isAbstract
returns true
for an interface. Which is fine for my use case, but probably not very helpful if one were trying to distinguish between a class, abstract class and an interface.