You are currently browsing the Philipp Meier's weblog blog archives for May, 2003

forum


newsterms

CollectionsUtils makes me think I need closures in Java

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 →

content
tour
Bear
content