Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - def addOne(f:Int = & gt; Int, arg: Int) = f(arg)+ 1, what does this code mean?
def addOne(f:Int = & gt; Int, arg: Int) = f(arg)+ 1, what does this code mean?
def addOne(f:Int = & gt; Int,arg: Int) = f(arg) + 1,

AddOne requires two parameters: passing an integer parameter and returning an integer method parameter, and the second parameter is an integer. The method body executes the method f with the first parameter, which is the second parameter of the method, and then returns the value of F+1 as the return value, which is equivalent to java:

int addOne(SomeObject f,int args){

Returns f.methodnname (args)+1;

}

Class SomeObject{

int method name(int a){

Return to a * a

}

}