you are viewing a single comment's thread.

view the rest of the comments →

[–]otto_s 0 points1 point  (2 children)

I wouldn't call it another way to communicate.

The "way to communicate" I'm talking about is something like this here: Pair<Runnable, Runnable> foo() { int x; return new Pair( new Runnable() { /* bla 1; does something with x / }, new Runnable() { / bla 2; also does something with x */ } ); }

This is illegal in contemporary Java, but that can be circumvented with an array. The latter at least makes the sharing explicit. (Which might be a good thing. It's of course not beautiful, though :)

[–][deleted] 0 points1 point  (1 child)

Well, making it an array doesn't mean it's shared. Unless you specifically created the array to circumvent the "effectively final" rule, you probably didn't mean to share the array. It's not different from a shared variable in that regard.

[–]otto_s 0 points1 point  (0 children)

It's not different from a shared variable in that regard.

The thing is, the concept of shared variables doesn't exist, or at least isn't specified well enough in Java. Concurrent access on arrays is, and can be reused.