Skip to end of metadata
Go to start of metadata

This is a good post which tries to demostrate the power of closures and functors.

It also helps illustrate how noisy things can be in Java. e.g.

whereas we could do something like this in Groovy

In IT you can usually use any tool to solve any problem. However sometimes switching tools makes things much easier & simpler.

  • No labels

1 Comment

  1. While closures in groovy are really cool. This example is doing a really bad job of making the point about java and the fuctors library. The following (much shorter) java code has the same result.

       UnaryPredicate isEligibleForDiscount = new UnaryPredicate() {
            public boolean test(Object obj) {
                SETLItem item = (SETLItem)obj;
                return "A".equals(item.getCategory()) && item.getPrice() > 200;
            }
       };   
    
       if (isEligibleForDiscount.test(item1)) {
          System.out.println("Item #1 is eligible for discount!");
       } else {
          System.out.println("Item #1 is not eligible for discount!");
       }