Join Slack
Powered by
Hello there :wave: , I have a question regarding c...
# announcements
j
Jiri Malina
01/08/2020, 7:55 AM
Hello there 👋 , I have a question regarding closures/lambdas in Kotlin. How come variables accessed from a closure in Kotlin don’t need to be final as oppose to Java where they need to be effectively final?
Jiri Malina
01/08/2020, 8:10 AM
https://stackoverflow.com/questions/44538627/why-the-code-in-an-object-expression-can-access-variables-from-the-scope-that-co/44538792#44538792
I found this, but I’m still curious about the implementation details. 🤔 Any pointers? 🙇
b
Benoît Liessens
01/08/2020, 8:11 AM
The non final vars are said to be captured by the lambda. The compiler generates a wrapper around the non finals and exposed those in the lambda
j
Jiri Malina
01/08/2020, 8:35 AM
👍 Awesome, thank you for clarifying this! I wanted to see the actual generated code. Sharing the results in case someone else would be interested:).
Open in Slack
Previous
Next