Effectively final effective?

Peter Levart peter.levart at marand.si
Thu Feb 25 01:00:30 PST 2010


On Thursday 25 February 2010 01:34:33 Neal Gafter wrote:
> On Wed, Feb 24, 2010 at 3:37 PM, Lawrence Kesteloot <lk at teamten.com> wrote:
> > The "final" modifier has bugged me in the past with anonymous inner
> > classes, but we really have no experience allowing large number of
> > programmers to write code without the restriction. For all we know it
> > would cause more confusion or more errors.
> 
> Scala and C# and Ruby programmers, and programmers in many other
> languages, live without this restriction.  Perhaps we should ask them.
>  In my experience it is a blessing compared to the Java alternatives.
> 
> One common pattern I've seen is the equivalent of
> 
> Type1 result1 = null;
> Type2 result2 = null;
> doSomeApi(#(){ result1 = someComputation(); result2 = otherComputation(); });
> doSomethingWith(result1, result2);
> 
> where doSomeApi might be something like Java's
> AccessController.doPrivileged(PrivilegedAction).
> 
> Cheers,
> Neal

First I'd like to say that I'm all for "transparent" access to variables from lambdas. It's realy the most natural way to program that way and I would like to see it implemented. But if concerned powers decide it is too much of a risk, then there should be something in the language to support explicit denotation of variable wrappers so that awkward workarrounds are not needed.

For example, how do you find this:

  final *volatile Type1 result1 = &null;
  final *Type2 result2 = &null;
  doSomeApi(#(){ *result1 = someComputation(); *result2 = otherComputation(); });
  doSomethingWith(*result1, *result2);

to be compiled as:

  final java.gen.VolatileObjectReference<Type1> result1 = new  java.gen.VolatileObjectReference<Type1>(null);
  final java.gen.ObjectReference<Type2> result2 = new  java.gen.ObjectReference<Type2>(null);
  doSomeApi(#(){ result1.referent = someComputation(); result2.referent = otherComputation(); });
  doSomethingWith(result1.referent, result2.referent);

or is this awkward too?


Regards, Peter


More information about the lambda-dev mailing list