[kotlin/en] lambda functions wrong defined (#5007)

lambda functions can not defined by `fun` directly, use `val` (or `var` if mutability is required) instead
This commit is contained in:
Risun 2024-07-23 15:55:15 +08:00 committed by GitHub
parent be1e100e38
commit ad6e1f09bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -124,7 +124,7 @@ fun helloWorld(val name : String) {
You can also use lambda functions, with the '->' operator seperating You can also use lambda functions, with the '->' operator seperating
the parameters from the function body. the parameters from the function body.
*/ */
fun fooLambda: (Int) -> Int = {n -> n + 1} val fooLambda: (Int) -> Int = {n -> n + 1}
println(fooLambda(1)) // => 2 println(fooLambda(1)) // => 2
// Functions can take functions as arguments and return functions. // Functions can take functions as arguments and return functions.