Reputation: 369
I have function which returns some value. In the function parameter I pass the same value:
fun getValue (value:String):String {
var message = value
value = "Hello"
return message
}
How can I call getValue
function in another function? For example:
fun getResult (){
var a = getValue (what here?)
}
Upvotes: 0
Views: 2470
Reputation: 553
You can pass a function as a prameter for another function in kotlin. Kotlin functions can take other functions in arguments, or even return them.
fun getResult (func:(String) -> String) {
//some code
var a = func("some string")
}
fun getValue (value:String):String {
var message = value
return message
}
and call getResult and pass function to it:
getResult({ getValue("Hello") })
Upvotes: 1