https://kotlinlang.org logo
#reflect
Title
# reflect
d

Dariusz Kuc

02/16/2022, 4:27 AM
Hello 👋 Just wondering if anyone knows how to detect whether given property is a lambda, e.g. given
Copy code
class Foo(val bar: () -> Bar)
// or
class Foo(val bar: suspend () -> Bar)
how to check whether
bar
is actually a lambda. I was hoping that simple
KProperty.returnType is Function<*>
would do the trick, sadly that returns false...
e

ephemient

02/16/2022, 4:29 AM
returnType is a KType, not a KClass or an instance
you could do something like
Copy code
returnType.isSubtypeOf(typeOf<Function<*>>())
👍 1
d

Dariusz Kuc

02/16/2022, 4:40 AM
nice that seems to do the trick
thanks
3 Views