Nice to @Share?

Mark Mahieu markmahieu at googlemail.com
Mon Feb 22 14:34:47 PST 2010


Well I don't know what the reasoning was behind the cases I spotted, but the ones I recall were synchronously invoked from a single thread, so there were a number of viable options, including the (well known, as Josh points out) local single-element array variable.

Perhaps the programmer(s) in question simply found the technique more tasteful than other forms of wrapper.

Mark


On 22 Feb 2010, at 22:08, Peter Reilly wrote:

> This is why AtomicInteger was invented
> 
> Peter
> 
> On Mon, Feb 22, 2010 at 10:02 PM, Mark Mahieu <markmahieu at googlemail.com> wrote:
>> 
>> On 22 Feb 2010, at 21:37, Joshua Bloch wrote:
>> 
>>> This requires programmers to use
>>> the well-known single-element array (or wrapper object) idiom in the rare
>>> case where they really do want to close over a mutable local variable.
>> 
>> That's an interesting point actually - how rare is it?  My gut feeling is that it's rather less rare than some of the other things we've discussed, but it might be useful to find out.
>> 
>> Whilst producing the statistics which Alex requested a couple of weeks ago, I noticed a few classes which might have been good candidates for lambdas but for the fact that they contained an additional field updated by the 'primary' method, along with a getter method to retrieve its value.
>> 
>> Mark
>> 
>> 
>> 



More information about the lambda-dev mailing list