Search |
||
Closure and collection integrationPosted by forax on September 8, 2006 at 12:39 AM PDT
The closure proposal doesn't define how closure and
collections will work together.
It's reasonable to say that this API will exist
because closure in order to be accepted
by the community must be well integrated with collections.
After all, java.util is the second more used package after
java.lang.
In a dream world, collection should have method like
forEach in their interface, but there is no way
to add a method in an existing interface without breaking
the sacredsanct backward compatibility.
List
In my opinon, there are two other ways to do something similar.
The first one consists in reversing the problem,
if you can't add a method on collection, you can
add it to closure.
List I'm not a big than of this solution, it's too PERL-like, you don't know what an instruction do without read the whole block.
The other solution is to defined methods that use closure
in a class like
java.util.Collections that already contains lot of
helper methods and to use an import static.
import static java.util.Collections.*; List Or with the inline syntax of the closure proposal : import static java.util.Collections.*; ListIn that case forEach is just another method in the class Collections.
package java.util;
public class Collections {
public <T,U> List<U> forEach(List<T> list,U(T) function) {
...
}
}
Any other ideas ? »
Related Topics >>
Open JDK Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|