Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top