From: bonefry Date: 2005-09-07T05:31:28+09:00 Subject: Re: ruby style blocks in java Those code blocks are really nice :-) But anyway, they are usefull not because they are elegant, but because they capture the context in which they are created. In Java only variables declared will be captured by an annonymous class, so if you want some variable in the current context, you can do something like this: final int[] tmpArray = new int[0]; Object someObject = new SomeObject(); tmpArray[0] = someObject; a.do(new Block() { public void yield(Object o) { // someObject is not captured in // here, but tmpArray is, // so you can use someObject by // accessing tmpArray[0] } }); Groovy looks good, and it is (much) faster that Ruby (from my own personal experience) but it is still too young, and although it's a JSR, it's programmers only work on their free time on it, so we will have to wait, and to be honest, right now the future does not look very bright for Groovy (it's only my oppinion, and I hope I'm wrong).