Skip to content
Justice Tech School

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

What is <T>?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.