August 2018
Beginner
178 pages
4h 56m
English
You can declare a generic class or interface with angle brackets after the type name. In the angle brackets, you specify the name of your generic type parameter. Usually, generic types are called T or E.
Let's see how the generic Array class is declared in the Kotlin Standard Library:
public class Array<T> { public inline constructor(size: Int, init: (Int) -> T) public operator fun get(index: Int): T public operator fun set(index: Int, value: T): Unit public val size: Int public operator fun iterator(): Iterator<T>}
Notice, how, in the generic type declaration, there is no information about the actual generic type argument. We only reserved a place for it and gave it a name, T. The actual generic type argument will ...
Read now
Unlock full access