Kotlin miniguide #17 Generics

Generic function :


fun <T> List<T>.itemAt ( position : Int) : T {

return this[position]

}

Generic class :


class Library <T> ( private books: List<T>) {

    val last : T? get () = books.lastOrNull()

}

More examples here

Lascia un commento