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

234 questions
5
votes
5 answers

How to implement python method with signature like ([start ,] stop [, step]), i.e. default keyword argument on the left

Since in python 3.X the build-id range() function returns no longer a list but an iterable, some old code fails as I use range()to conveniently generate lists I need. So I try to implement my own lrange function like this: def lrange(start = 0,…
Rafael T
  • 15,401
  • 15
  • 83
  • 144
5
votes
1 answer

What's the format for `objc_method_description.types` for swift blocks?

The Objective-C method encoding produced by the Swift compiler for swift methods with blocks seems to use syntax not documented anywhere. For instance the method: func DebugLog2(message: String) async -> String has the method…
5
votes
10 answers

Array of functions with different signatures

I have this classes: class Foo { ... }; class Foo1 : public Foo { ... }; ... class FooN : public Foo { ... }; Is it possible to have an array of functions with these kind of signatures: void f1(Foo1*){} ... void fN(FooN*){} Is there…
Mircea Ispas
  • 20,260
  • 32
  • 123
  • 211
5
votes
4 answers

searching for c++ code parser to see all signatures

I'm looking for a c++ parser which is able to extract all the functions and methods with its signatures. Is there something like this? I had a look at gccxml there I have the problem, that it is not able to use namespaces and its not fine when only…
develhevel
  • 3,161
  • 4
  • 21
  • 27
5
votes
5 answers

Why can't two methods be declared with the same signature even though their return types are different?

Duplicate: Function overloading by return type? Maybe this is a very silly question but I don't understand why I can't declare two methods that have the same signature when they have different return types. public class MyClass { private double…
mezoid
  • 28,090
  • 37
  • 107
  • 148
5
votes
1 answer

calling COM method with Foo(..., [out] BSTR * value) from VBScript

Ist it possible to cal a COM method with the signature HRESULT Foo(BSTR in, [out] BSTR * out1, [out] BSTR * out2) from VBScript? The following: Dim a; Dim b; component.Foo "something", a, b gives an error about incompatible types. I still…
peterchen
  • 40,917
  • 20
  • 104
  • 186
5
votes
2 answers

Add multiple key values in context.Context from web services API

I have a web application written in Go with multiple modules, one deals with all database related things, one deals with reports, one consists all web services, one for just business logic and data integrity validation and several others. So, I have…
rsudip90
  • 799
  • 1
  • 7
  • 24
5
votes
2 answers

What is in and out on delegate in c#?

In c# code, i found this implement. I tried to find out what this in and out meaning, but only explanation of out keyword in there. So what these in and out keyword do? public delegate Tb Reader( Ta a );
JaeWoo So
  • 568
  • 5
  • 18
5
votes
1 answer

Method signature arguments of type(self)

When I define a class, how can I include arguments in its methods' signatures which have to be of the same class? I am building a graph structure which should work like this, but here is a simplified example: class Dummy: def __init__(self,…
Elias Mi
  • 611
  • 6
  • 14
5
votes
1 answer

Java Bytecode Signatures

As part of the compiler for the programming language I am working on, I came across generic signatures in the bytecode, which I am trying to parse and convert to an AST. The parsing algorithm mostly works, but there seems to be a special case in…
Clashsoft
  • 11,553
  • 5
  • 40
  • 79
5
votes
2 answers

C#: Method signatures?

Let's say I create these two methods: public void AddScriptToPage(params string[] scripts) { /*...*/ } public void AddScriptToPage(string href, string elementId) { /*...*/ } Which one of these methods gets call by the code below, and…
JamesBrownIsDead
  • 4,655
  • 6
  • 30
  • 29
5
votes
3 answers

Generics, Nullable, Type inference and function signature conflict

I've this code : public async static Task RequestValue1(Command requestCommand) where T : struct { // Whatever } public async static Task RequestValue2(Command requestCommand) where T :…
Nicolas Voron
  • 2,916
  • 1
  • 21
  • 35
5
votes
1 answer

Determining if an Objective-C method is variadic during runtime

Is there a way to find out -- at runtime -- whether a given method is of variadic type? Something like method_getTypeEncoding(); that won't tell me whether a method accepts variable number of arguments. Or is there maybe a trick to tell so?
5
votes
3 answers

What is the difference between the generic signifier ' and the symbol ^ In F# method signatures

I understand the tick to signify a generic parameter, as in: Seq.append : seq<'T> -> seq<'T> -> seq<'T> but what does the caret signify, as in: Seq.average : seq<^T> -> ^T
Joshua Belden
  • 10,273
  • 8
  • 40
  • 56
4
votes
1 answer

Type encoding string for protocol method

I'm trying to get a signature -- either an NSMethodSignature object or at least the type encoding string -- for a method declared in a protocol. Asking the Protocol object itself isn't possible, since a) it doesn't implement…
jscs
  • 63,694
  • 13
  • 151
  • 195