Method and function calls

About functions and methods using simple parameters of each other

{Demo02 Object
DEF main (args: the Array [String]): Unit = {
Val F1 = (A: Int, B: Int) => A + B
// define a two parameters of type int and returns a value of Int function
Val F2 = (a: Int, B: Int) => a + B
F2 (1,2)
// call the method passing a function f1
the println (M1 (f1))
// call the function f1 passing method two , parameters A, B
the println (M2 (f1,1,2))
// call the method passed three parameters A, B
the println (M3 (l, 3))
// call the function F1
the println (F1 (l, 3))
}
// methods of a parameter definition must be the type of the return value Int also two types 1Int
DEF M1 (F: (Int, Int) => Int): Int = F (2,6)
// define a data is the method becomes
DEF M2 (F: (Int, Int) => Int, a: Int, B: Int): Int = F (a, B);
// define a method of two types of parameters Int
def m3 ( a: Int, b: Int) : Int = a + b

}

Guess you like

Origin blog.csdn.net/weixin_44701192/article/details/91474021