Nice to @Share?

Gernot Neppert mcnepp02 at googlemail.com
Tue Feb 23 03:09:21 PST 2010


2010/2/23 Reinier Zwitserloot <reinier at zwitserloot.com>:
> "public" as a keyword on local variable declarations and method parameters
> avoids the need to mess with (restricted) new keywords, is backwards
> compatible, and there is some (but admittedly not a lot) semantic harmony
> between public fields and methods, and local variables that end up declared
> on the heap, potentially accessible by multiple threads, etc
>

Well, at least it is more self-explanatory than the proposed annotation @Shared.
And, as you say, having a "real" keyword for a modifier with such vast
implications seems appropriate!

But I wouldn't allow it on method parameters, though. Modifying method
parameters directly is bad coding style, IMHO.
One could argue that method parameters should have been "final" by
default in the first place.

Apart from that, it worries me a little that in the future there would
be 2 ways of achieving access to local variables from anonymous inner
classes + lambdas: "final" and "public". You'd have to teach
programmers that if they needed read access only, they could use both
but were strongly encouraged to use "final".

Then you'd have to go into detail to explain why ("declaring a
variable public entails the creation of a special-class heap object
which will be auto-boxed and unboxed every time the variable is being
accessed")...


More information about the lambda-dev mailing list