Complete the code to declare an inline function with a reified type parameter.
inline fun <[1]> printTypeName() { println("Type: ${T::class.simpleName}") }
reified keyword causes a compilation error.inline inside the angle brackets instead of before the function.The reified keyword allows access to the type T at runtime inside an inline function.
Complete the code to check if an object is of type T using a reified type parameter.
inline fun <reified T> isType(value: Any): Boolean {
return value is [1]
}is check causes an error.Any instead of T.Using value is T inside an inline function with a reified type parameter allows type checking at runtime.
Fix the error in the function to get the class name of type T using reified type parameters.
inline fun <reified T> getClassName(): String {
return [1]::class.simpleName ?: "Unknown"
}T.class which is Java syntax and invalid in Kotlin.T::class.java which returns a Java class, not Kotlin class.Inside an inline function with a reified type parameter, T::class is valid, but here the code uses T::class.simpleName. The blank expects T to use T::class.simpleName.
Fill both blanks to create a function that returns a list of elements filtered by type T using reified type parameters.
inline fun <reified T> filterByType(list: List<Any>): List<[1]> { return list.filterIsInstance<[2]>() }
String or Int instead of the generic T.The function uses the reified type parameter T to filter elements of that type from the list.
Fill all three blanks to create an inline function that casts a value to type T or returns null if the cast fails.
inline fun <reified T> safeCast(value: Any): [1]? { return value as? [2] ?: [3] }
Unit instead of null on cast failure.The function returns the value cast to T or null if the cast fails, using the safe cast operator as?.