Generics
Type parameters make classes and functions work with many types.
Example
class Box<T>(val value: T)
fun <T> first(list: List<T>): T = list[0]
println(Box(5).value)
println(first(listOf("a", "b")))Exercise
Type parameter.
class Box<>
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.