100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Kotlin

Default and Named Arguments in Kotlin

Simplify function calls in Kotlin using default parameter values and named arguments instead of overloads.

Functions & LambdasBeginner7 min readJul 8, 2026
Analogies

Introduction

In many languages, calling a function with fewer arguments than parameters requires writing multiple overloaded versions of that function. Kotlin avoids this with default arguments, which let a parameter fall back to a preset value when the caller doesn't supply one. Kotlin also supports named arguments, which let you specify which parameter a value belongs to by name rather than by position, making calls clearer and more flexible.

🏏

Cricket analogy: A net bowler always defaults to leg-spin unless the captain names a different variation like googly, so Bumrah doesn't need five separate practice sessions scheduled for every possible delivery type.

Syntax

kotlin
fun greet(name: String, greeting: String = "Hello") {
    println("$greeting, $name!")
}

// Calling with a named argument, out of order
greet(greeting = "Hi", name = "Sam")

Explanation

The parameter greeting has a default value of "Hello", so callers can omit it entirely and Kotlin will use the default. When calling greet(greeting = "Hi", name = "Sam"), the arguments are matched by name instead of position, so their order in the call doesn't need to match the order in the function declaration. This is especially useful for functions with many parameters, since it removes the need to create several overloaded versions just to handle different combinations of arguments.

🏏

Cricket analogy: When Kohli calls for field=deep, bowler=spin out of order, the captain still matches each instruction to the right fielder by label, just as greet(greeting="Hi", name="Sam") matches by name not position.

Example

kotlin
fun createUser(name: String, age: Int = 18, isAdmin: Boolean = false) {
    println("Name=$name, Age=$age, Admin=$isAdmin")
}

fun main() {
    createUser("Alice")
    createUser("Bob", 25)
    createUser(name = "Carol", isAdmin = true)
}

Output

kotlin
Name=Alice, Age=18, Admin=false
Name=Bob, Age=25, Admin=false
Name=Carol, Age=18, Admin=true

Key Takeaways

  • Default arguments are assigned using = in the parameter list.
  • Callers can skip parameters that have default values.
  • Named arguments let you specify parameters by name, in any order.
  • Combining defaults and named arguments reduces the need for function overloads.
  • Named arguments improve readability, especially with boolean or numeric parameters.

Practice what you learned

Was this page helpful?

Topics covered

#Kotlin#KotlinProgrammingStudyNotes#Programming#DefaultAndNamedArgumentsInKotlin#Default#Named#Arguments#Syntax#StudyNotes#SkillVeris