Answer
The signature of a method is the combination of the method's name along with the number and types of the parameters (and their order).
Is this item
helpful? yes no
Previous votes Yes: 1 No: 1
|
|
Comments and alternative answers
 |
method signature
Josh Downes, Jan 16, 2003 [replies:1]
I was kind of hoping for an example. Is this one:
myMethod(int i, int j);
// does the signature include the ';'?
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|

|
 |
incomplete, thus incorrect
Deepak Kenchamba, Jun 16, 2004 [replies:11]
Specific to java, The signature of a method should contain more details. It should contain
1. Visibility modifier (public, private, protected)
2. Return type
3. Name of the method
4. Arguments (type, order)
5. Throws clause
Deepak Kenchamba.
Is this item
helpful? yes no
Previous votes Yes: 2 No: 2
|
|

|
 |
 |
 |
Why the return type is not included in the method signature?
emil dinchev, Feb 9, 2006 [replies:5]
Look at the following code (it is illegal):
public class A {
public Object getSomething() {
return new Object();
}
public String getSomething() {
return new String();
}
}
A a = new A();
Object o = a.getSomething();
String s = a.getSomething();
I'm wondering why this code is not permitted. The compiler can detect the expected return type of the method and to use the correct method during the call.
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|

|
 |
 |
 |
 |
Re: Why the return type is not included in the method signature?
paul t, Apr 3, 2006 [replies:2]
I am not sure what you expect as an answer this code wont work coz you are not obeying the rules of method overloading. In method overloading you need to change the arguments(which in this case is none) but not the return type.....
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|

|
 |
 |
 |
 |
 |
 |
Re[3]: Why the return type is not included in the method signature?
Eric Sun, Jun 5, 2006
I think Emil's question is a good question. I think Emil knows that signiture does not include return type, but why Java does include return type in signature so that it is more convenient for programmers to do the overload? Let me try to answer here, I am not sure whether it is a good answer:
1. Signiture of a method is an identifier for JVM to identify where to locate the method in memory or steak, so that it can branch to that method. Java uses method name and parameters as identifier. If two method with the same signiture, compiler will say "you are wrong, identifier need to be unique, I don't know where to go if you give two same identifiers".
2. Again, why do not include return type in the signiture? I think you all have the experience that you can make a function call with checking the return or discarding the return. To have this flexibility, method and paramters of the method combination has to be unique.
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|

|
|
|
 |
|