August 2017
Intermediate to advanced
440 pages
10h
English
Functions have parameters (variables declared inside a function declaration) and arguments (the actual value that is passed to a function). Similar terminology applies to generics. A type parameter is a blueprint or placeholder for a type declared in a generic, and a type argument is an actual type used to parametrize a generic.
We can use a type parameter in a method signature. This way, we can make sure that we will be able to add items of a certain type to our list and retrieve items of a certain type:
class SimpleList<T> {
fun add(item:T) { // 1
// code
}
fun get(intex: Int): T { // 2
// code
}
}
Read now
Unlock full access