```inline fun <reified C> name() = C::class....
# codereview
c
Copy code
inline fun <reified C> name() = C::class.simpleName

name<Collection<String>>()
this returns “Collection”. is there a way make it return “Collection<String>“?
j
You lose the element type information as soon as you do
C::class
, because the
KClass
type simply doesn't have that information. What you need is
KType
, which you can get from a reified
C
using
typeOf<C>()
. I don't know off the top of my head how to get a nice string for its name from the
KType
, but you might be able to figure that out
c
ah typeOf was exactly what I need, thanks
e
KType.toString()
will get you
kotlin.collections.Collection<kotlin.String>
if you want the simple names you'll have to walk through it yourself, I don't think there's a built-in utility for it