Tom said:
I believe the signature includes neither the return type nor the
exceptions thrown, just the method name and the types of the
parameters. This is discussed in the JLS (in 8.4.3 in the 3rd
edition). E.g.,
"Two methods have the same signature if they have the same name and
argument types."
See <
http://java.sun.com/docs/books/jls/third_edition/html/
classes.html#8.4.2>
You are correct. However, it is still useful to think of return type and
exception types as part of the signature. If you don't respect those, you can
get compiler errors. So informally I think of the signature as including
those factors.
For example, if you declare two methods in a class with the same signature,
it's a compiler error. If you declare two methods that differ only in
(non-covariant) return type, you get an error. If you add checked exceptions
to a method override, you get an error. The mental dodge of pretending that
exceptions and return types are part of the signature helps me keep that straight.
Still, it is pretending. You are right about the definition.