core-libs-dev Digest, Vol 13, Issue 1

David M. Lloyd david.lloyd at redhat.com
Mon May 5 14:15:32 UTC 2008


On 05/05/2008 09:09 AM, Neal Gafter wrote:
> On Mon, May 5, 2008 at 5:54 AM, David M. Lloyd <david.lloyd at redhat.com> wrote:
>> On 05/03/2008 08:40 AM, Paulo Levi wrote:
>>
>>> Is it possible to make the java.sql interface Connection, Statement and
>>> ResultSet descend from closeable?
>>>
>>  Not that I'm aware of, since SQLException doesn't extend IOException.  That
>> said, it might be nice to have a java.sql.Closeable for some future JDBC...
>>
>>  I guess once you have that, you could do a java.lang.Closeable with a close
>> method that throws Exception, and derive both java.io.Closeable and
>> java.sql.Closeable from that. :-)
> 
> I think you want Closeable to be something like
> 
>   interface Closeable<X extends Exception> {
>     void close() throws X;
>   }
> 
> Deciding how to do this is more of a Java SE specification issue than
> an OpenJDK implementation issue.

Not really - I mean, this is more complex than it needs to be.  You could 
just have:

    void close() throws Exception;

on the base (java.lang perhaps?) interface, and override with the existing

    void close() throws IOException;

in java.io.  Similarly covariant interfaces could exist elsewhere too.  The 
problem with introducing generics on the base interface is that if you want 
to inherit it from more than once place, you can't - even if the desired 
exception type is a subclass of all the specified parent interfaces.  Using 
generics where basic covariance can work introduces more problems than it 
solves.

- DML



More information about the core-libs-dev mailing list