wood burning stoves 2.0
The moose likes Beginning Java and the fly likes method signature Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "method signature" Watch "method signature" New topic

method signature

Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
Hi Kathy and Bert and all the ranchers
I have read some books answer following
The method signature including
The name of the method and
The parameter list of the method
But without the return type
Does the method signature including the return type?
For Kathy and Bert
Does the book contain both of your signature as well if I win the book?
Because I can not go to the book shop which both of you will be there.
thanks for your attention

Francis Siu
Kevin Gilchrist

Joined: Oct 24, 2002
Posts: 4
The signature depends on whether you're overriding or overloading the methods.
The difference is described on one of the Sun tutorials as:
"Overloading and Overriding
As you construct classes and add methods to them, there are circumstances when you will want to reuse the same name for a method. There are two ways that you can do this with Java. Reusing the same method name with different arguments and perhaps a different return type is known as overloading. Using the same method name with identical arguments and return type is known as overriding. "
The full article is at:
[ June 04, 2003: Message edited by: Kevin Gilchrist ]
Greedy thomas
Ranch Hand

Joined: May 15, 2003
Posts: 37
Hello Siu
A short answer to your question about method signature. Yes - The method signature does include the return type.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
The return type is not part of the signature.
JLS 15.12.2:
The second step searches the class or interface determined in the previous step for method declarations. This step uses the name of the method and the types of the argument expressions to locate method declarations that are both applicable and accessible, that is, declarations that can be correctly invoked on the given arguments. There may be more than one such method declaration, in which case the most specific one is chosen. The descriptor (signature plus return type) of the most specific method declaration is one used at run time to do the method dispatch.
The return type is part of the method descriptor, but not part of the method signature.

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
Original post of the following
I am not sure the signature of method overloading

Let me show some example why I confuse
1: void getRid(int i,int j);
2: void getRid(int i,float j);
3: int getRid(int i,float j);
4: int getRid(int i,int j);
If all of the four methods put in the interface,does the compiler give me an error message? It means that ARE all of the four methods are different.
But my teacher material show me that the method overloading only includes the name of the method and the parameter list of the method , IS this material WRONG
thanks again

After Michael answer
now without any doubts
The first time edit
[ June 04, 2003: Message edited by: siu chung man ]
The second time edit
thanks Layne
I am busy(exam including Java) within two weeks,so I am lazy that without using compiler
[ June 04, 2003: Message edited by: siu chung man ]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Your teacher is correct: only the name and parameters are part of the signature. As stated earlier, the return type is NOT part of the signature. If you put all four of the example methods you posted into the same class or interface, the compiler will complain. (Go ahead and try it for yourself.)

Java API Documentation
The Java Tutorial
It is sorta covered in the JavaRanch Style Guide.
subject: method signature