mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
[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:
parent
be1e100e38
commit
ad6e1f09bc
@ -124,7 +124,7 @@ fun helloWorld(val name : String) {
|
||||
You can also use lambda functions, with the '->' operator seperating
|
||||
the parameters from the function body.
|
||||
*/
|
||||
fun fooLambda: (Int) -> Int = {n -> n + 1}
|
||||
val fooLambda: (Int) -> Int = {n -> n + 1}
|
||||
println(fooLambda(1)) // => 2
|
||||
|
||||
// Functions can take functions as arguments and return functions.
|
||||
|
Loading…
Reference in New Issue
Block a user