Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ********example via String
- fun main() {
- myFunction("Hi",::justShow)
- }
- fun myFunction(name:String, myFunc:(String)->Unit){ // must be ->, because differ from regular function declaration
- println("It is an example of higher order function")
- }
- fun justShow(firstName:String):Unit{
- }
- //************same but more details
- fun main() {
- myFunction("Hi",::justShow)
- }
- fun myFunction(name:String, myFunc:(String)->Unit){ // must be ->, because differ from regular function declaration
- println("$name, It is an example of higher order function")
- justShow("Now")
- }
- fun justShow(firstName:String):Unit{
- println("$firstName, It's my call")
- }
- // ********example via Int
- fun main() {
- myFunction(5,::justShow)
- }
- fun myFunction(number: Int,unused:(Int,Int)->Int){
- println(justShow(7,9))
- println("$number")
- println(justShow(72,5))
- }
- fun justShow(number:Int, firstNumber: Int):Int=number+firstNumber
Add Comment
Please, Sign In to add comment