This message was deleted.
# getting-started
s
This message was deleted.
s
is
is used to check types of instances - if you want to match on a
KClass<T>
then you just need to use
when
like you would when comparing other values
Copy code
when (type) {
  String::class  -> ...
  Int::class -> ...
}
👍 2
but I’m not sure if smart-casting would work here - usually a check on a generic type doesn’t work like this because of JVM type erasure
m
Ummm, what are you trying to do here? Feel like I'm missing something. What meaning would
type.length
have on a KClass even if it's wrapping a String? Don't you want
Copy code
val type:Any

when(type) {
    is String -> println(type.length)
    is Int -> prinlnt(type * 2)
    is Boolean -> {}
    else -> {}
}