Questions tagged [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. A method signature is the smallest type of a method.

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. A method signature is the smallest type of a method.

Method overloading

Method signatures can be used by the compiler to distinguish between methods with the same name, but with different parameters. This is called . The precise characteristics of method overloading depends on the programming language. Overloading should not be used for methods that perform an different operation as that will make the source code hard to read.

Examples

Example of declarations of two overloaded methods with the same name, but with a different method signature:

void drawPoint(int x, int y);
void drawPoint(Point p);

in this case it is likely that drawPoint(x, y) internally converts x and y into a Point instance. This kind of function is therefore called a convenience method.

Related questions

210 questions
166
votes
1 answer

Static member functions error; How to properly write the signature?

I am getting an error when trying to compile my code in g++ using the current signature: cannot declare member function static void Foo::Bar(std::ostream&, const Foo::Node*) to have static linkage My question is twofold: Why does it not Compile…
Joshua
  • 4,040
  • 9
  • 37
  • 59
103
votes
14 answers

Does a method's signature in Java include its return type?

Does the method signature in a Java class/interface include its return type? Example: Does Java know the difference between those two methods: public class Foo { public int myMethod(int param) {} public char myMethod(int param) {} } Or is…
faressoft
  • 17,177
  • 42
  • 96
  • 138
56
votes
6 answers

Inheritance best practice : *args, **kwargs or explicitly specifying parameters

I often find myself overwriting methods of a parent class, and can never decide if I should explicitly list given parameters or just use a blanket *args, **kwargs construct. Is one version better than the other? Is there a best practice? What…
Maik Hoepfel
  • 1,589
  • 1
  • 12
  • 19
49
votes
7 answers

How to get method signatures from a jar file?

I have a third-party jar file that comes with the javadocs for only part of the API. Is there a way to reverse engineer the jar file to obtain a complete listing of classes and methods?
MCS
  • 20,445
  • 20
  • 56
  • 76
47
votes
5 answers

How to return an array from a function?

How can I return an array from a method, and how must I declare it? int[] test(void); // ??
ewggwegw
  • 3,852
  • 5
  • 23
  • 26
30
votes
5 answers

C++ typedef member function signature syntax

I want to declare type definition for a member function signature. Global function typedefs look like this: typedef int (function_signature)(int, int); typedef int (*function_pointer) (int, int); But I'm not able to the same thing for a member…
0xbadf00d
  • 14,584
  • 15
  • 60
  • 93
29
votes
6 answers

Compute a Java function's signature

Is there a way to compute a Java class's method's signature? A signature like ([Ljava/lang/String;)V represents a function that takes a String[] as argument and returns void. What's the rule to compute the signature?
Niklas R
  • 14,369
  • 23
  • 82
  • 179
25
votes
4 answers

Why are jQuery's callback arguments inconsistent?

A common pattern within jQuery is a method that takes a callback which is passed an element of an array and its index within that array. However, it seems completely random which argument comes first. For example, from the jQuery docs at…
brad
  • 67,670
  • 21
  • 67
  • 84
23
votes
7 answers

Definition of a method signature?

What is the correct definition of a method signature (or a signature of a method)? On google, I find various definitions: It is the combination of the method name and the parameter list Does that mean method signature = method name + argument…
KMC
  • 18,443
  • 53
  • 146
  • 238
22
votes
3 answers

Is it possible to pass a method as an argument in Objective-C?

I have a method that varies by a single method call inside, and I'd like to pass the method/signature of the method that it varies by as an argument... is this possible in Objective C or is that too much to hope for?
eriaac
  • 943
  • 2
  • 8
  • 7
22
votes
5 answers

Why varargs should be the last in method signature?

If I try to write a method like below public void someStuff(Object ... args, String a ) I get this error The variable argument type Object of the method someStuff must be the last parameter. I don't fully understand the requirement of variable…
Ravi Gupta
  • 4,217
  • 12
  • 49
  • 84
19
votes
2 answers

What is "override-equivalence" and how is it related to @Override?

Reading the Javadoc for the @Override annotation, I came across the following rule: If a method is annotated with this annotation type compilers are required to generate an error message unless at least one of the following conditions…
17
votes
4 answers

Delegate for any method type - C#

I want to have a class that will execute any external method, like this: class CrazyClass { //other stuff public AnyReturnType Execute(AnyKindOfMethod Method, object[] ParametersForMethod) { //more stuff return…
Daniel Möller
  • 74,597
  • 15
  • 158
  • 180
16
votes
1 answer

What are the digits in an ObjC method type encoding string?

I'm reading Apple's article about Objective-C runtime type encoding strings and some methods have numbers in their type strings. What do the numbers in v12@0:4@8 mean?
Ecir Hana
  • 9,122
  • 13
  • 58
  • 105
15
votes
6 answers

Call function in c++ dll without header

I would like to call a method from an dll, but i don't have the source neither the header file. I tried to use the dumpbin /exports to see the name of the method, but i can found the methods signature? Is there any way to call this method? Thanks,
mileschet
  • 351
  • 1
  • 7
  • 13
1
2 3
13 14