can accept function as Parameter
can return Function as Parameter
or can do both
fun main(args : Array<String>)
{
var addy : (Int,Int) -> Int = {x,y ->x+y}
var a = show()
a.see(7,8,addy) //all 3 are same
a.see(10,20,{x,y ->x+y})
a.see(45,73) {x,y ->x+y}
}
class show
{
fun see(a:Int,b:Int,action:(Int,Int)->Int)
{
var result = action(a,b)
println(result)
}
}
It :-
Implicit name of Single Parameter
fun main(args:Array<String>)
{
val program = Program()
program.reverseanddisplay("Hello,{it.reversed()}) //use of it
}
class Program(str : String, myFunc : (String) -> String) {
var result = myFunc(str)
println(result) }}
No comments:
Post a Comment