forEach broken in build 48?
Mike Duigou
mike.duigou at oracle.com
Wed Jul 25 19:12:10 PDT 2012
I've looked into the problem and am able to replicate it. I did some debugging and it appears to be a problem in the VM. I am notifying those working on this area.
Mike
On Jul 21 2012, at 01:39 , Arul Dhesiaseelan wrote:
> 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