Pick the fix
This doesn't compile: 'Cannot check for instance of erased type T'. What's the fix?
fun <T> List<Any>.firstOfType(): T? =
firstOrNull { it is T } as T?Hint 1 of 1
What does reified require?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Make it inline fun <reified T> List<Any>.firstOfType(): T?
Correct. reified needs inline, and then is T works.
Why not the others?
- B Add
@Suppress("UNCHECKED_CAST"). Suppressing a warning doesn't make an erased check possible. - C Use
T::class.javainstead. Also needs reified. - D Make T non-null with
T : Any. The type is still erased.