Skip to main content

Kotlin Functions

Define functions with default, named and vararg parameters, single-expression, local, tailrec and infix functions.

1
Kotlin Functions

Defining Function and Its Type Kotlin Program

A function is a block of code written to perform a task. A Kotlin example with source code and sample output.

2
Kotlin Functions

Simple Function Example Kotlin Program

A function is a block of code written to perform a task. A Kotlin example with source code and sample output.

3
Kotlin Functions

Parameterized Function Example Kotlin Program

A function is a block of code written to perform a task. A Kotlin example with source code and sample output.

4
kotlin functions

Default Parameters in Kotlin

Function parameters can declare default values so callers may omit them. A Kotlin example with source code and sample output.

5
kotlin functions

Named Parameters in Kotlin

Callers can pass arguments by parameter name for clarity. A Kotlin example with source code and sample output.

6
kotlin functions

Vararg Parameters in Kotlin

A vararg parameter accepts zero or more values of the same type. A Kotlin example with source code and sample output.

7
kotlin functions

Single Expression Functions in Kotlin

When a function body is a single expression, you can use the = syntax. A Kotlin example with source code and sample output.

8
kotlin functions

Local Functions in Kotlin

A function declared inside another function is called a local function. A Kotlin example with source code and sample output.

9
kotlin functions

tailrec Functions in Kotlin

tailrec marks a recursive function that calls itself as the last operation. A Kotlin example with source code and sample output.

10
kotlin functions

Infix Functions in Kotlin

An infix function is called without dot notation between the receiver and argument. A Kotlin example with source code and sample output.

Related Topics

Search tutorials