1. The function has no beneficial protein type. The return type is Unit. 2. You can set the default values.
private fun doSomething(flag:Boolean,age:Int =2):String{
return "result"+age+flag
}
Copy the code
3. The position of the passed parameter can be changed:
fun main(){
doSomething(true)
doSomething(true,1)
doSomething(age = 1,flag = true)
}
private fun doSomething(flag:Boolean,age:Int =2):String{
return "result"+age+flag
}
Copy the code
Special functions. The quotation marks
Fun main () {` fun ` ()} fun ` fun ` () {println (" I am special function ")}Copy the code
5. Anonymous functions that return the last line of code without retrun
println({a: Int, b: String -> "Welcome to SimVillage, $a! (copyright $b)" }(2019, "Benny"))Copy the code
6. Anonymous function type inference. The following is an anonymous function that returns a String. The parameter type can also be omitted.
Var bessingFunction={a:String,b:Int -> "} print(bessingFunction("ss",1)Copy the code