Does Exception specification is a part of method signature? What I mean is:
public void someMethod(String myString) throws IOException
is 'throws IOException' a part of a signature of this method?
Thanks
Following up on Jon Skeet's answer and in response to the comment
@ Jon Skeet Why then I cant have public void run() throws IOException in a class which implements Runnable? – Knowing me knowing you
Section 8.4.6 of the Java Language Specification (3rd ed) says:
A method that overrides or hides another method (Section 8.4.8), including methods that implement
abstract
methods defined in interfaces, may not be declared to throw more checked exceptions than the overridden or hidden method.More precisely, suppose that B is a class or interface, and A is a superclass or superinterface of B, and a method declaration n in B overrides or hides a method declaration m in A. If n has a
throws
clause that mentions any checked exception types, then m must have athrows
clause, and for every checked exception type listed in thethrows
clause of n, that same exception class or one of its supertypes must occur in the erasure of thethrows
clause of m; otherwise, a compile-time error occurs.
It's not a matter of method signature here, but a matter of not requiring callers to account for exceptions that aren't required to be checked by the 'original' method they are calling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With