Search⌘ K
AI Features

Generic Functions

Explore how to define and use generic functions in Kotlin by working with type parameters. Understand the conventions for naming type parameters and learn how the compiler infers types for safer code. This lesson helps you create flexible and reusable functions that improve code reliability and developer experience.

Type parameters

Just as we can pass an argument value to a parameter, we can pass a type as a type argument. For this, a function needs to define one or more type parameters inside <> brackets immediately after the fun keyword.

Tip: By convention, type parameter names are capitalized.

  • When a function defines a type parameter, we have ...