// Created on savesnippets.com ยท https://savesnippets.com/nSbzFFR3cv9Pj0 class Box(val value: T) { fun map(f: (T) -> U): Box = Box(f(value)) } // Generic function with a type bound fun > max(list: List): T { var best = list[0] for (item in list) if (item > best) best = item return best } // Multiple bounds via `where` fun copyIfNotNull(src: T?, dst: T) where T : Cloneable, T : java.io.Serializable { /* ... */ } fun main() { val intBox: Box = Box(42) val strBox: Box = intBox.map { it.toString() } println(strBox.value) // "42" println(max(listOf(3, 1, 4, 1, 5, 9, 2))) // 9 println(max(listOf("apple", "banana", "cherry"))) // "cherry" }