Reputation: 1794
I have java SDK 7 installed and i am using Eclipse 3.7.1 Indigo.
When i use the new Java 7 syntax for defining a HashMap, it works fine.
HashMap<Integer, Integer> hashMap = new HashMap<>();
But when i try to use closure syntax, eclipse throws compile errors. This is what i am trying to compile.
public static <T> Collection<T> select(Collection<T> source,
{T=>Boolean} predicate) {
Collection<T> result = new ArrayList<T>();
for (T o : source) {
if (predicate.invoke(o)) {
result.add(o);
}
}
return result;
}
Is the syntax wrong? or Am i doing it wrong?
Upvotes: 0
Views: 718
Reputation: 1502406
Java 7 doesn't have closures - it's a planned feature for Java 8.
It was hoped that it would be in Java 7, but it didn't make the cut.
Upvotes: 9