Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dvt32/a98ebeb6cd859c189208a3c9cf577353 to your computer and use it in GitHub Desktop.
Save dvt32/a98ebeb6cd859c189208a3c9cf577353 to your computer and use it in GitHub Desktop.
class ExampleClass {
fun printDetails(firstName: String = "John", lastName: String = "Doe", yearsOfExperience: Int = 5) {
println("First name: $firstName, Last name: $lastName, Years of experience: $yearsOfExperience")
}
fun myMethod() {
printDetails() // uses default values
printDetails("Bob", "Johnson", 5) // classic Java way
printDetails(firstName = "Bob", yearsOfExperience = 10) // with named params, some can be skipped
printDetails(lastName = "Johnson", yearsOfExperience = 7, firstName = "Bob") // order can be switched
}
fun doStuff(
name: String = "John",
greeting: String = "$name, welcome home!" // you can access other params' values like this
) {
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment