I am correct in understanding how anonymous functi...
# announcements
c
I am correct in understanding how anonymous functions works in Kotlin?
i
I would consider what happens if this anonymous function is in-pure - it access something from outside function
Copy code
val shift = 2

val add2 = fun (x: Int, y: Int): Int {
    return x + y + shift
}
As I recall this is how variables val/var variables captured by lambda are stored:
val
- value is copied to anonymous class
var
- value is stored in anonymous class as a reference to class that holds value
c
That's nice. Haven't thought about it. Thanks for this
i
BTW you may just compile Kotlin class and then decompile it using Java decompiler http://jd.benow.ca/
c
That doesn't show the result what I am expecting. Instead of the real anonymous class, it shows something like add2 = (Function2) add2.1.INSTANCE
i
Hard to say. Either Kotlin compiler is optimised or decompiled code is somehow messed up. Can’t help more here.