https://kotlinlang.org logo
Title
j

Jasin Colegrove

01/27/2022, 12:52 PM
I have a SimpleListProperty<T>, how can I do a when (t) { is T -> todo() } how to extract the Type contained in the list property?
j

Joffrey

01/27/2022, 12:55 PM
Where are you trying to write this
when
? Could you give a bit more context? How do you get the instance of
SimpleListProperty<T>
and what is
t
here? In general, if this class itself doesn't give access to the class of
T
, you can't. It is erased, so at runtime all you see is
SimpleListProperty
, not
SimpleListProperty<String>
. However, depending on how/where you want to use this information, using
reified
types may enable you to still get the information.
j

Jasin Colegrove

01/27/2022, 1:07 PM
fun <T: Entity<T>> createLog(
    filename: String,
    logType: LogType,
    entityList: SimpleListProperty<T>,
    projectNum: SimpleStringProperty,
    projectName: SimpleStringProperty
I pass it to the function, T is an Entity<T> from ktorm, they are database entires.
inside the function I want to know T so I call another function that will process the entries based upon the type of entry they are
actually I see what I can do now, I can just use logType. I'm dumb
:rubber_duck: 1
👌 1