https://kotlinlang.org logo
Title
m

mike_shysh

06/27/2019, 10:52 AM
Hi, if an argument in some function is
Class<T> type
Is it possible to provide List<ObjectA>.class (seems such syntax is not ok in kotlin)?
d

diesieben07

06/27/2019, 10:57 AM
ObjectA::class
gives you the
KClass
,
ObjectA::class.java
gives you the
Class
. However because generics are erased,
List<ObjectA>::class
is not allowed because it does not make sense.
👍 1
m

mike_shysh

06/27/2019, 10:58 AM
Thanks, got it
if you use a library that allows some sort of TokenType you can do this some it
d

diesieben07

06/27/2019, 11:00 AM
Kotlin reflection now has
typeOf
, which is a nicer way of doing that
👌 1
d

Dias

06/27/2019, 11:02 AM
typeTokenOf()?
m

mike_shysh

06/27/2019, 11:02 AM
Actually, I don't need to pass object. Initial library from my question accepts custom comparator for type. I tried to find a way, to compare two lists in a custom way)
d

diesieben07

06/27/2019, 11:02 AM
no, just
typeOf
, which gives you a
KType
not sure what the library does, but if it's based on
Class
, there is no way to tell it to compare
List<A>
differently from
List<B>
, because both of those are just
List
at runtime.
m

mike_shysh

06/27/2019, 11:04 AM
I got it, thanks. Lack of deep knowledge on generics(