Working with CollectionUtils’s Predicate makes me think: I need closures in Java. Consider the following code snippets of equvalent Java and Ruby code.
Java:
public List test(List data) {
LinkedList result = new LinkedList;
for(Iterator i = data.iterator(); i.hasNext();) {
Address address = (Address) i.next();
if("Germany".equals(address.getCountry())) {
result.add(address);
}
}
return result;
}
And ruby:
def test(data)
return data.collect { |address|
"Germany".equals(address.getAddress)
}
}
Continue reading ‘CollectionsUtils makes me think I need closures in Java’