Timur Atakishiev
10/06/2020, 7:41 AMinline fun <reified T> isTypeOf(any: Any?): Boolean {
return any is T
}
val isTypeOf: Boolean = isTypeOf<Collection<String>>(Any)
my Any is ArrayList of String.diesieben07
10/06/2020, 7:42 AMList<String>
from a List<Any>
, there is only List
.Timur Atakishiev
10/06/2020, 7:42 AMdiesieben07
10/06/2020, 7:44 AMList<String>
to String
). But I could be wrong on that.Vampire
10/06/2020, 7:58 AMVampire
10/06/2020, 7:58 AMprintln(arrayListOf(Object()) is Collection<String>)
will give compiler error Cannot check for instance of erased type: Collection<String>
Vampire
10/06/2020, 7:59 AMTimur Atakishiev
10/06/2020, 7:59 AMVampire
10/06/2020, 8:00 AMVampire
10/06/2020, 8:00 AMVampire
10/06/2020, 8:00 AMtrue
Vampire
10/06/2020, 8:00 AMTimur Atakishiev
10/06/2020, 9:11 AMVampire
10/06/2020, 9:17 AMdiesieben07
10/06/2020, 9:43 AMval collection: MutableCollection<Any> = listOf("Hello World")
val isStringCollection = collection.all { it is String } // true, even though it's not