Complete the code to declare a generic class that holds a value of any type.
class Box<[1]>(val value: T)
The generic type parameter is declared using T inside angle brackets.
Complete the function signature to make it generic over type T.
fun <[1]> printValue(value: T) { println(value) }Generic functions declare their type parameter before the function name using <T>.
Fix the error by specifying the correct generic type in the list declaration.
val numbers: List<[1]> = listOf(1, 2, 3)
The list contains integers, so the generic type must be Int for type safety.
Fill both blanks to create a generic function that returns the first element of a list.
fun <[1]> firstElement(list: List<[2]>): [1]? = list.firstOrNull()
The function uses the same generic type T for the parameter and return type to ensure type safety.
Fill all three blanks to create a generic class with a method that returns the stored value.
class Container<[1]>(private val item: [2]) { fun getItem(): [3] = item }
The generic type T is used consistently to ensure the class stores and returns the same type safely.