https://kotlinlang.org logo
#getting-started
Title
# getting-started
r

Ray Rahke

03/09/2024, 5:07 AM
So obviously I am doing this wrong, but I am not sure how to get it working.
h

hfhbd

03/09/2024, 6:26 AM
sevenIsInstanceOf(Int::class)
otherwise you pass the implicit companion object of Int. But your function won’t work anyway, you can’t use a typed
KClass
with the
is
operator, you have to use
type.isInstance(7)
. Or without a class parameter using the `Type`:
Copy code
inline fun <reified T> sevenIsInstanceOf(): Boolean {
    return 7 is T
}

sevenIsInstanceOf<Int>()
2 Views