forEach broken in build 48?

Arul Dhesiaseelan aruld at acm.org
Sat Jul 21 01:39:50 PDT 2012


Hi,

It looks like forEach is broke in the latest build. It always prints the
last item in the collection. It works fine in b45. It works in b48 only if
we expand the code, not if we perform method reference on an instance.

public class InstanceMethodReference {

    public static void main(String[] args) {
        Arrays.asList("Alice", "Bob", "Charlie",
"Dave").forEach(System.out::println);//INCORRECT RESULT
        Arrays.asList("Alice", "Bob", "Charlie", "Dave").forEach(new
MyBlock(System.out));//CORRECT RESULT
    }

    public static class MyBlock implements Block<String> {
        PrintStream ps;

        public MyBlock(PrintStream ps) {
            this.ps = ps;
        }

        @Override
        public void apply(String s) {
            ps.println(s);
        }
    }
}

build45 correctly prints:
Alice
Bob
Charlie
Dave
Alice
Bob
Charlie
Dave

build48 prints:
Dave
Dave
Dave
Dave
Alice
Bob
Charlie
Dave


-Arul


More information about the lambda-dev mailing list