- Method signature
-
In computer programming, especially object-oriented programming, a method is commonly identified by its unique method signature, which usually includes the method name, and the number, types and order of its parameters.[1] A method signature is the smallest type of a method.
Contents
Examples
C/C++
In C/C++, the method signature is the method name and the number and type of its parameters, but it is possible to have a last parameter that consists of an array of values:
int printf(const char*, ...);
Manipulation of these parameters can be done by using the routines in the standard library header <stdarg.h>.
C#
Similar to the C syntax, C# sees as the method signature its name and the number and type of its parameters, where the last parameter may comprise of an array of values:[2]
void Add(out int sum, params int[] value); [...] Add(out sum, 3, 5, 7, 11, -1); // sum == 25
Java
In the Java programming language, a method signature is the method name and the number and type of its parameters. Return types are not considered to be a part of the method signature.
methodName(parameters) {...};
For example, the following two methods have distinct signatures:
doSomething(int y); doSomething(String y);
The following two methods do have the same signatures and are considered the same, as only the return value differs. The name of the parameter is not part of the method signature and is ignored by the compiler for checking method uniqueness.
int doSomething(int y) String doSomething(int x)
Objective-C
In the Objective-C programming language, method signatures for an object are declared in the interface header file. For example,
- (id)initWithInt:(int)value;
defines a method initWithInt that returns a general object (an id) and takes one integer argument. Objective-C only requires a type in a signature to be explicit when the type is not id; this signature is equivalent:
- initWithInt:(int)value;
References
- ^ Paul Leahy. "Method Signature". http://www.about.com/: About.com Guide. http://java.about.com/od/m/g/methodsignature.htm. Retrieved 2011-05-31. "A method signature is part of the method declaration. It is the combination of the method name and the parameter list."
- ^ Mössenböck, Hanspeter (2002-03-25). "Advanced C#: Variable Number of Parameters". http://ssw.jku.at/Teaching/Lectures/CSharp/Tutorial/: Institut für Systemsoftware, Johannes Kepler Universität Linz, Fachbereich Informatik. p. 52. http://ssw.jku.at/Teaching/Lectures/CSharp/Tutorial/Part1.pdf. Retrieved 2011-08-03.
External links
- Defining Methods in Sun's Java Tutorials
Categories:- Programming language topic stubs
- Method (computer science)
Wikimedia Foundation. 2010.