Created
August 21, 2022 11:34
-
-
Save dvt32/a98ebeb6cd859c189208a3c9cf577353 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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