Local function updating two vars of enclosing method
Posting from the bus so I'll keep it short.
If a local function needs to access and update a local var of the enclosing method, the compiler has to translate the 开发者_如何转开发latter into an object, so it can be passed around.
What if it updates two local vars? Are these translated into 2 objects? Or 1 object with 2 fields. I guess the first one, which is simpler to implement, but I would be more confident having the 2nd approach, essentially an optimization, implemented.
Thanks
For now (2.9), indeed, two separate “holder” objects are used by the Scala compiler to capture the two vars in your closure.
精彩评论