If I have a `inline fun <reified T: Any?> fo...
# announcements
r
If I have a
inline fun <reified T: Any?> foo()
, where at my call-site
T
is a
List<Something>
, is there a way to determine
Something
inside the inline fun?
f
Unless you're sending the list to the function as a parameter or you're willing to have a more "precise" function for that case, I don't think so
something like
inline fun <reified L, reified T: List<L>> fooList()
Otherwise you could do
Copy code
inline fun <reified T: Any?> foo(t: T){
    if (T::class.isSubclassOf(List::class)) {
        val list = t as List<*>

        if (list.isNotEmpty()) {
            val itemType = list.first()!!.javaClass
        }
    }
}
but that's slightly dodgy
r
Yeah, I like the more precise function approach...