https://kotlinlang.org logo
Title
a

Anthony Flores

04/28/2022, 9:45 PM
How can I use
is
with generics? For example if the generic is
<T : SomeClass>
how can check if T is a specific child of
SomeClass
?
j

Joffrey

04/28/2022, 10:00 PM
is
cannot check the type
T
, it can only check an instance of
T
, so you would have to have an instance or a
KClass<T>
to do what you want
a

Anthony Flores

04/28/2022, 10:04 PM
In my case, I have a class which returns an instance of
T
, however it is the super class. It also isn't always ensured that the returned value is an instance of
T
, so I want to check if that is the case, and then create an instance of
T
with the properties of the returned values.
m

myanmarking

04/28/2022, 10:10 PM
Use reified inline
a

Anthony Flores

04/28/2022, 10:11 PM
I get "Cannot use
T
as reified param"
j

Joffrey

04/28/2022, 10:46 PM
Can you share some code of your setup, I am not entirely sure I understand your situation, especially the part where the instance of
T
is not guaranteed to be one