jeggy
10/09/2018, 2:22 PMfun <T> test(list: List<T>) = when (list) {
is List<String> -> println("Hello World")
is List<List<Int>> -> println("Deep")
else -> println("No Clue")
}
diesieben07
10/09/2018, 2:23 PMList
, so this check is not possible.ribesg
10/09/2018, 2:23 PMfun test(list: List) = when (list) {
is List -> println("Hello World")
is List -> println("Deep")
else -> println("No Clue")
}
Shawn
10/09/2018, 2:25 PMCannot check for instance of erased type
jeggy
10/09/2018, 2:25 PMjeggy
10/09/2018, 2:25 PMEgor Trutenko
10/09/2018, 2:25 PMEgor Trutenko
10/09/2018, 2:26 PMelizarov
10/09/2018, 2:26 PMdata class ListOfStrings(val list: List<String>)
& etc — use those instead of plain lists & you’ll be able to check their types.Shawn
10/09/2018, 2:28 PMis List<T>
check valid - you can match against T::class
, but that would likely fail against the List<List<Int>>
caseterorie
10/09/2018, 2:34 PMlist
to List<Any>
, then check if list[0] is String/List