> The one trick is to realize that the safe version is actually the more
> specific one. If you think of the exception in terms of the type union
> (not accurate, but a decent analogy), then Unsafe.method() returns
> void|IOException while Safe.method() returns void, which is a more
> specific type, thus the return types are co-variant.

I think Reinier was refering to this:

x.doSomething(new StringReader("xyz"));
x.doSomething(someUnsafeReader());

Unless you have two overloads of doSomething both invocations will
throw an IOException. Having two overloads is code duplication though.
Even if it looks like that:

public void doSomething(SafeReader r) {
    try {
        doSomething((UnsafeReader)r);
    } catch(IOException e) {
        throw new RuntimeException(e);
    }
}

With kind regards
Ben
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to