Comment on Closures for JavaparentComments−maddalab16yyes, but that syntax is unnecessary as the proposal allows for final variables (primitives and reference types) to be available in the function literal syntaxfinal int a = 0;is all you need in the example you provide.−gchpaco16yNot if you want to change the value of a.−bad_user16yAnd that's not the only case.For instance you may want "a" to be mutable, but you also want to use its value when the closure gets executed.I don't think I've ever used a framework in Java that relies on event-handlers / callbacks where I didn't had to box local variables.
Comments
yes, but that syntax is unnecessary as the proposal allows for final variables (primitives and reference types) to be available in the function literal syntax
final int a = 0;
is all you need in the example you provide.
Not if you want to change the value of a.
And that's not the only case.
For instance you may want "a" to be mutable, but you also want to use its value when the closure gets executed.
I don't think I've ever used a framework in Java that relies on event-handlers / callbacks where I didn't had to box local variables.