Skip to content

Instantly share code, notes, and snippets.

@cutiko
Created June 25, 2020 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cutiko/4196886a9c151206b1d0d9b90a61ae8b to your computer and use it in GitHub Desktop.
Save cutiko/4196886a9c151206b1d0d9b90a61ae8b to your computer and use it in GitHub Desktop.
A function as default value for argument in function, the default value function has also argument, wonders of Kotlin
class FunctionDefaultValue {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val result = foo(2)
println(result)
}
fun foo(int: Int, boolean: Boolean = bar(int)): String {
return "$int $boolean"
}
fun bar(int: Int) = int % 2 == 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment