Skip to the content.

Generics

Kotlin allows both use-site variance and declaration-site variance.

Parametric Type Constraints - where

fun <T: AutoCloseable> useAndClose(input: T) = input.close() // T should confirm to one type

// T confirm to multiple types
fun <T> useAndClose(input: T) where T: AutoCloseable, T: Appendable {
  input.append("something")
  input.close()
}

Inline Functions and Reified Types

🔗 Inline functions