Too bad the optimization isn't that smart: ```var ...
# getting-started
k
Too bad the optimization isn't that smart:
Copy code
var mainCount = 0
mainCount++

thread {
    while( true ) {
        println(mainCount)
        Thread.sleep(1000)
    }
}
could work without reference too, but the compiler generates it anyway.
s
Thx, how would it work without reference?
fun testLambda( block : () -> Unit ) { thread { while( true ) { block() Thread.sleep( 1000 ) } } }
k
Well in my example
mainCount
isn't modified after it "leaks", so no reference is needed.
s
If mainCount was passed by value to the generated class, how would the generated class see the latest value?
Oh ok, got it