I actually prefer @Cleanup to the JDK 7 proposal in that it presumably just cleans up at the end of the variable's scope ala C++.
If you need ordering amongst several @Cleanup variables, then you can always introduce {...} scoping, right? If so, then I'd rather introduce such things only as needed rather than the JDK 7 proposal's approach. Roel Spilker wrote: > Casper, > > You are correct. I just wanted the other readers to know that it is > not limited to "close". It is however limited to no-args methods. > > Roel > > > On Sep 1, 4:10 pm, Casper Bang <casper.b...@gmail.com> wrote: > >> I think you misunderstood Roel. I am aware of the method name argument >> override, I was merely exploring the different implementations and >> implications of these two ARM blocks. The JDK7 version would have to >> rely on a new interface Disposable being added to the libraries, as >> the abomination known as checked exceptions (IOException) once again >> gets in the way of simply using the existing Closable. Lombok couldn't >> care less what it's closing and could in fact be used as a C++ >> deconstructor. Correct? >> >> /Casper >> >> On 1 Sep., 15:47, Roel Spilker <r.spil...@gmail.com> wrote: >> >> >>> Caster, that is not entirely correct. The "close" methode (actually, >>> close is just the default, you can specify an other method name if you >>> want) will be called when the variable goes out of scope. >>> Unfortunately, java does not allow an annotation on a code block. So >>> an equivalent programm would be: >>> >>> { >>> @Cleanup InputStream in = new FileInputStream(...); >>> // Do something else... >>> >>> } >>> >>> On Sep 1, 3:10 pm, Casper Bang <casper.b...@gmail.com> wrote: >>> >>>> The neat thing about this is that we do not have to wait until the >>>> Java API has been retrofitted with the Disposable interface. However, >>>> you won't get the scope limitation benefits (the in and out variable >>>> is scoped the whole method). I kind of wish we could use annotations >>>> on blocks, so this would be possible instead: >>>> >>>> @Cleanup{ >>>> InputStream in = new FileInputStream( ... ); >>>> // Do something... >>>> >>>> } >>>> >>>> @Cleanup{ >>>> InputStream in = new FileInputStream( ... ); >>>> // Do something else... >>>> >>>> } >>>> >>>> /Casper >>>> >>>> On 1 Sep., 14:53, Roel Spilker <r.spil...@gmail.com> wrote: >>>> >>>>> For ARM-blocks you can have a look at the @Cleanup annotation of >>>>> Lombok and have ARM-blocks for Java right now! >>>>> >>>>> The following code will close both streams correctly after they run >>>>> out of scope. >>>>> >>>>> import lombok.Cleanup; >>>>> import java.io.*; >>>>> >>>>> public class CleanupExample { >>>>> public static void main(String[] args) throws IOException { >>>>> @Cleanup InputStream in = new FileInputStream(args[0]); >>>>> @Cleanup OutputStream out = new FileOutputStream(args[1]); >>>>> byte[] b = new byte[10000]; >>>>> while (true) { >>>>> int r = in.read(b); >>>>> if (r == -1) break; >>>>> out.write(b, 0, r); >>>>> } >>>>> } >>>>> >>>>> } >>>>> >>>>> Seehttp://projectlombok.org/features/Cleanup.htmlformore >>>>> information >>>>> >>>>> On Sep 1, 2:19 pm, "joel.neely" <joel.ne...@gmail.com> wrote: >>>>> >>>>>> According to coverage >>>>>> athttp://arstechnica.com/apple/reviews/2009/08/mac-os-x-10-6.ars/10 >>>>>> , Snow Leopard, the latest version of Mac OS X, added "blocks" to C. >>>>>> The article illustrates this new language construct with the by-now >>>>>> canonical ARM and home-grown-control-structure examples. >>>>>> >>>>>> Hey, Java! Closures to the left of me [JRuby, Scala, etc.], blocks to >>>>>> the right [C on OS X], here I am, stuck in the middle with you! >>>>>> > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to javaposse@googlegroups.com To unsubscribe from this group, send email to javaposse+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/javaposse?hl=en -~----------~----~----~----~------~----~------~--~---