let's play TDD, tackles closures in java

Bourriaud Gérard gerardbourriaud at gmail.com
Sun Dec 19 00:41:40 PST 2010


*Hello*
*The AtomicBoolean is seems a good idea, but please don't make any mapping,
don't do stupid things like C++  add the capacity to overide ++, -- +=, +,
...  and so on. This operators MUST stay for primitive type like int,
boolean, short, ...*
* The mapping is not shorter is just add confusion*
*Lambda can be use for pass method as argument, but not for change the
object way of thinking. Don't fall in C++ bad  way of coding please.*
*
*
*The advantage of Lambda is not the SAM, the real advantage I see is to be
able do a same mtehod in different context for exemple :*
*
*
*public interface class Context*
*{*
*    public int doSomethingInContext(int parameter, #int(int) method);*
* *
*}*
*
*
*public class DirectContext implements Context*
*{*
*   public int doSomethingInContext(**int parameter, **#int(int) method)*
* {*
* return method(parameter();*
* }*
*}*

public class ReentrantContext extends ReentrantLock implements Context
{
   public int doSomethingInContext(int parameter, #int(int) method)
   {
       this.lock();
      try
      {
          return method(parameter);
      }
      finally
      {
           this.unlock();
      }
   }
}


And can be use like that :

Context contextDirect = new DirectContext();
Context contextReentrant = new ReentrantContext();

int integer = 0;
int result1 = contextDirect.doSomethingInContext(integer, #{ i -> i+1 });
int result2 = contextReentrant.doSomethingInContext(integer, #{ i -> i+1 });

....

object = ...
context.doSomethingInContext(integer, #{ i -> object.method(i) });

...



Regards,
Gérard


More information about the lambda-dev mailing list