What is the correct definition of method signature?

H

hiwa

Does the term method signature have different definitions depending on
context?

JLS 8.4.2 --- This may be compiler's view.
<quote>
Two methods have the same signature if they have the same name and argument
types. --- 3rd edition
</quote>
Description from the second edition is a little bit longer than this but
the sense is the same.

JLS 12.3.3 --- This may be linker's view.
<quote>
NoSuchMethodError: A symbolic reference has been encountered that refers
to a specific method of a specific class or interface, but the class or
interface does not contain a method of that signature. --- 3rd edition
</quote>
NoSuchMethodError checks the return type of method as a part of signature.

If I repeat the question in other words:
Isn't there a one single formal/official definition for the term method
signature in Java or in a standard CS theory?
 
R

Ross Bamford

Does the term method signature have different definitions depending on
context?

JLS 8.4.2 --- This may be compiler's view.
<quote>
Two methods have the same signature if they have the same name and argument
types. --- 3rd edition
</quote>
Description from the second edition is a little bit longer than this but
the sense is the same.

JLS 12.3.3 --- This may be linker's view.
<quote>
NoSuchMethodError: A symbolic reference has been encountered that refers
to a specific method of a specific class or interface, but the class or
interface does not contain a method of that signature. --- 3rd edition
</quote>
NoSuchMethodError checks the return type of method as a part of signature.

If I repeat the question in other words:
Isn't there a one single formal/official definition for the term method
signature in Java or in a standard CS theory?

From the point of view of the language, A method signature doesn't
include the return type at all, which is why you cannot overload on
return type alone.

I don't understand what you mean by 'NoSuchMethodError checks the return
type', but in any case that exception is part of the JVM implementation
of Reflection (etc). Consider that when you look for a method
reflectively, you only pass in it's parameter types and name, and these
are look the method up.

Ross
 
T

Tony Morris

hiwa said:
Does the term method signature have different definitions depending on
context?

JLS 8.4.2 --- This may be compiler's view.
<quote>
Two methods have the same signature if they have the same name and argument
types. --- 3rd edition
</quote>
Description from the second edition is a little bit longer than this but
the sense is the same.

JLS 12.3.3 --- This may be linker's view.
<quote>
NoSuchMethodError: A symbolic reference has been encountered that refers
to a specific method of a specific class or interface, but the class or
interface does not contain a method of that signature. --- 3rd edition
</quote>
NoSuchMethodError checks the return type of method as a part of signature.

If I repeat the question in other words:
Isn't there a one single formal/official definition for the term method
signature in Java or in a standard CS theory?

The method name, the order and type of parameters.
You have found (yet another) ambiguity in the JLS, which makes it unclear.
It is imperative that the order of the parameters as well as the type is
explicitly stated as one aspect that contributes to a 'method signature'.

--
Tony Morris
Software Engineer, IBM Australia.
BInfTech, SCJP 1.4, SCJP 5.0, SCJD

http://www.jtiger.org/ JTiger Unit Test Framework for Java
http://qa.jtiger.org/ Java Q&A (FAQ, Trivia)
http://xdweb.net/~dibblego/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top