This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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
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: http://developer.java.sun.com/developer/Books/certification/page3.html [ June 04, 2003: Message edited by: Kevin Gilchrist ]
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
Joined: Jan 04, 2003
Original post of the following hum.... 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 thanks 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 ]
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.) HTH Layne