`KType.classifier` will give you that, but it does...
# reflect
d
KType.classifier
will give you that, but it does not have to be a
KClass
, it could be a
KTypeParameter
. There is also
KType.jvmErasure
, which will loose type information though.
v
I still can't do
when(consP.type.classifier) { is kotlin.String -> \\... }
though, as I still have incompatible types.
d
Yes,
classifier
is a
KClassifier?
. The type might not be a pure
KClass
.
v
Hmm, perhaps what I want is not possible then. I really just want to know if my constructor's parameter accepts a kotlin.String or not. If it does, I'll just pass in my string value. If it does not, I'll call another function.
d
Well, the problem is not as simple as you might think. Assume you have this class:
Copy code
class MyClass<T>(value: T)
You can pass in a
String
only if
T
is
String
, but that is not knowable at runtime, since generics are erased.
v
OK. I'll have a think about my approach. I think Spring MVC manages it, somehow, but it's been a while since I've written much Spring code.
d
Spring will "blow up" in the scenario I mentioned as well. If you want Spring's behavior,
jvmErasure
is what you want I think.
v
Cheers. More to read!