@Shared warning
Neal Gafter
neal at gafter.com
Mon May 19 08:53:39 PDT 2008
The warning is given on any use of a local variable inside a closure if that
variable is modified anywhere (inside or outside of the closure).
On Mon, May 19, 2008 at 1:43 AM, Zdenek Tronicek <tronicek at fel.cvut.cz>
wrote:
> If we declare a closure with read-only access to a local variable, there is
> no warning:
>
> int n = 10;
> { => int } f = { => n };
>
> If a closure modifies the variable captured
>
> { => int } f = { => n--; n == 0 ? 1 : f.invoke() };
>
> there is a warning (which is right). But why is the warning also on place
> where the variable is read only?
>
> Recursion.java:17: warning: [shared] captured variable n not annotated
> @Shared
> { => int } f = { => n--; n == 0 ? 1 : f.invoke() };
> ^
> Recursion.java:17: warning: [shared] captured variable n not annotated
> @Shared
> { => int } f = { => n--; n == 0 ? 1 : f.invoke() };
> ^
> 2 warnings
>
> Z.
> --
> Zdenek Tronicek
> Department of Computer Science and Engineering
> Prague tel: +420 2 2435 7410
> http://cs.felk.cvut.cz/~tronicek <http://cs.felk.cvut.cz/%7Etronicek>
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/closures-dev/attachments/20080519/395e9609/attachment.html
More information about the closures-dev
mailing list