Feedback and comments on ARM proposal (original) (raw)

Howard Lovatt howard.lovatt at iee.org
Wed Mar 18 17🔞48 PDT 2009


Hi All,

2009/3/19 Neal Gafter <neal at gafter.com>:

[snip]

It's not even compatible to remove a throws clause from a non-overridable method!  That's because it would break callers who invoke it in a try-catch statement.

I am not proposing to do this, I am proposing adding the new interface to existing classes if you can and if you can't then wrap the existing class in a new one. I am not proposing modifying existing interfaces at all. This is a deliberate attempt to start again with resources and provide a unified model. For example suppose as Neal has suggested that the foreach loop understood resources, it would be great to write something like:

for ( final String line : AutoResources.asLines( filename ) ) { ... }

where

public class AutoResources { private AutoResources() {}

   public static FileAsLines asLines( final String filename )

throws FileNotFoundException { return new FileAsLines( filename ); }

   public static class FileAsLines implements AutoResource,

Iterable { private final FileReader reader;

       FileAsLines( final String filename ) throws

FileNotFoundException { reader = new FileReader( filename ); }

       public void autoDispose() {
           try { reader.close(); }
           catch ( IOException e ) { throw new IllegalStateException( e ); }
       }

      public Iterator<String> iterator() { return new

Iterator() { ... }; } }

   ...

}

(Note, in a previous post I have suggested that replacing keyword new when applied to an AutoResources with a new keyword, autoresource, this additional change would make this foreach example even clearer.)

In the above code there is no attempt to retrofit AutoResource to FileReader, instead it is wrapped.



More information about the coin-dev mailing list