This is closely related to, but is not the same question as: Java - Method name collision in interface implementation
When there are two Java interfaces that share a method with almost the same signature like so:
import java.io.IOException;
interface ISomething1 {
void doSomething();
}
interface ISomething2 {
void doSomething() throws IOException;
}
class Impl implements ISomething1, ISomething2 {
public void doSomething() {
throw new IOException(); // this does not compile since ISomething1.doSomething does not declare a throws clause
}
public static void main(String args[]) throws IOException {
Impl i = new Impl();
i.doSomething();
}
}
Why is it that Java enforces that only a single method implement both these interface methods even though technically they differ in signature?
Note also that in the example above, the implementation of Impl.doSomething
needs to NOT throw an IOException
as otherwise the compiler complains that ISomething1.doSomething must also declare that it throws IOException effectively making the throws clause in ISomething2.doSomething useless.
Am I missing something obvious here? Thanks in advance for responses.