Implementing recursive lambda with MethodHandle

Rémi Forax forax at univ-mlv.fr
Mon Feb 22 10:50:33 PST 2010


Le 22/02/2010 19:38, Joshua Bloch a écrit :
> Alex,
>
> On Mon, Feb 22, 2010 at 10:11 AM, Alex Blewitt <alex.blewitt at gmail.com 
> <mailto:alex.blewitt at gmail.com>> wrote:
>
>
>     I'm not sure why a temporary assignment to 'thisFn' is an better
>     than using 'this' in place - on the other hand, if one wanted to,
>     one could do both the above and the below.
>
>           #i(int i) {
>               #int(int) thisFn = this;
>               return i == 0 ? 1 : i * thisFn.(i - 1);
>            };
>
>
> It eliminates the circularity in the definition of the type of the 
> lambda: it's clearly #int(int). It's visual clutter, but at least it 
> doesn't clutter up the enclosing namespace.
>
>             Josh

This one doesn't clutter up the enclosing scope too :)

#(int i) {
     return new Object() {
       int sum(int x) {
         return (x==0)?0:x + sum(x-1);
       }
     }.sum(x);
};

Rémi



More information about the lambda-dev mailing list