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
10
votes
3 answers

What does this signature mean (&) in PHP?

Consider: public function & get($name, $default = null) Why &?
user198729
  • 61,774
  • 108
  • 250
  • 348
9
votes
7 answers

Final keyword in method signatures

Possible Duplicate: Final arguments in interface methods - what’s the point? While trying to experiment a few things, I've ran into a problem that it's described in this page. interface B { public int something(final int a); } abstract class…
SHiRKiT
  • 1,024
  • 3
  • 11
  • 30
9
votes
3 answers

How to specify any newable type in TypeScript?

I tried with this but it doesn't work. Foo is just a test of what works. Bar is the real try, it should receive any newable type but subclasses of Object isn't valid for that purpose. class A { } class B { public Foo(newable: typeof A):void { …
Áxel Costas Pena
  • 5,886
  • 6
  • 28
  • 59
8
votes
2 answers

Overload resolution, which method is called

Lets suppose I have a ComponentBase class, who is child of ObjectContextDecorator and grandchild of ObjectContext. public class ComponentBase extends ObjectContextDecorator { } public class ObjectContextDecorator extends ObjectContext { public…
Gabriel Robaina
  • 709
  • 9
  • 24
8
votes
3 answers

Tool to look for incompatabilities in method signatures / fields

I would like to be able to compare two versions of a class / library to determine whether there have been any changes that might break code that calls it. For example consider some class Foo that has a method in version a: public String…
M. Jessup
  • 8,153
  • 1
  • 29
  • 29
8
votes
2 answers

C++: inheriting overloaded non-virtual method and virtual method both with the same name causes problem

I am trying to inherit two equally named methods with different parameter lists to a derived class. One of them is virtual and overridden in the derived class, the other one is non-virtual. Doing so, i get a compile error while trying to access the…
Emme
  • 83
  • 1
  • 3
8
votes
2 answers

Delegates and ParamArray - Workaround Suggestions?

Some predefined methods contain a ParamArray in their signature. Delegates, however, cannot contain a ParamArray in their signature. Question: Assume you wish to create a delegation mechanism for a specific method which requires a ParamArray. How…
M.A. Hanin
  • 8,044
  • 33
  • 51
8
votes
1 answer

What is difference between Generic type and Object in method declaration?

I am confused that which method Signature should I use for same purpose? Both are working fine for me. 1. public T findUniqueByCondition(String tableName, String key, …
Vishal Zanzrukia
  • 4,902
  • 4
  • 38
  • 82
8
votes
7 answers

Can Java methods return type Enum?

I could be wrong but I'm guessing from Why can't enums be declared locally in a method? that, since an enum in Java cannot be declared locally, that therefore it is problematic for a method to return type Enum? I can declare that a method should…
Dexygen
  • 12,287
  • 13
  • 80
  • 147
6
votes
2 answers

static imports method overlap

if you have a class with a static import to java.lang.Integer and my class also has a static method parseInt(String) then which method will the call parseInt("12345") point to? Thanks in Advance!
MozenRath
  • 9,652
  • 13
  • 61
  • 104
6
votes
2 answers

Java - Is it possible to output the stacktrace with method signatures?

Is it possible to output the current stacktrace with method signatures? I'm trying to debug some obfuscated code that has a ton of methods with the same name that just differ in arguments and return type. Some things that will not…
jli
  • 6,523
  • 2
  • 29
  • 37
6
votes
3 answers

Interface implementation with method argument superclasses

As a practical example of the general question in the subject, I'd like to implement the containsAll method in the Set interface with public boolean containsAll(Iterable c) { /* ... */ } I figure this should be allowed, since Collection is…
Carl
  • 7,538
  • 1
  • 40
  • 64
6
votes
2 answers

Sublime PHP method signature and description on autocomplete

I really like sublime but I have 1 major issue stopping me from migrating from Netbeans: I need sublime autocomplete to show function description and method signature (i'm working with Yii framework and I need to know exactly what each function…
5
votes
2 answers

Why is varargs always the last parameter in a method signature?

Why does varargs have to be the last parameter in method signature? I want to know the reason.
Sam
  • 6,770
  • 7
  • 50
  • 91
5
votes
3 answers

How to get parameter names with Java reflection

How do I get method signatures with Java reflection? EDIT: I actually need the parameter NAMES not the types of a method.
javatar
  • 4,542
  • 14
  • 50
  • 67
1 2
3
15 16