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
14
votes
5 answers

How can an interface include a method that references the concrete implementation type of the interface in its signature or return type?

Suppose I am designing something like the following interface: public interface MyInterface{ public MyInterface method1(); public void method2(MyInterface mi); } However, there is the caveat that the return type for method1 and the parameter…
Michael McGowan
  • 6,313
  • 6
  • 37
  • 69
12
votes
4 answers

How can I make perltidy work with Method::Signatures?

I'm using Eclipse combined with EPIC to write my Perl code. I configured EPIC to use Perltidy with "-pbp" (perl best practices style) to format my code. This doesn't work well when using Method::Signatures' named parameters. E.g., func (:$arg1, :…
David B
  • 26,728
  • 46
  • 126
  • 177
12
votes
3 answers

Why does Stream.Write not take a UInt?

It seems highly illogical to me that Stream.Write uses int, instead of UInt... Is there an explanation other than "legacy" code for this fact? Would any one want to write -1 bytes?!?
Leonardo
  • 8,477
  • 8
  • 47
  • 119
12
votes
5 answers

Android studio breadcrumb method signature

I am looking for Breadcrumb functionality like Eclipse in Android Studio. In Eclipse Breadcrumb shows "method signature" when pointer(cursor) come inside whereas in Android Studio Breadcrumb is good for nothing. Please find attached for better…
Amit Yadav
  • 27,106
  • 6
  • 36
  • 46
12
votes
12 answers

Design question: pass the fields you use or pass the object?

I often see two conflicting strategies for method interfaces, loosely summarized as follows: // Form 1: Pass in an object. double calculateTaxesOwed(TaxForm f) { ... } // Form 2: Pass in the fields you'll use. double calculateTaxesOwed(double…
Kyle Kaitan
  • 1,731
  • 3
  • 19
  • 28
11
votes
6 answers

How should be my Service method signature?

I'm using a Service Layer, and until now I used a ServiceObject (which implements ArrayAccess, Iterator, Countable) but I'm wondering if it's a good ideas. Would you do: ArticleService::createArticle($articleData, $userId); or…
JohnT
  • 947
  • 2
  • 16
  • 30
11
votes
4 answers

How to generate method signature?

Desired output examples: (Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node; (Ljava/lang/String;)Lorg/w3c/dom/Attr; Such signatures can be generated using javap utility: javap -s -p org.w3c.dom.Node But is there any way to generate them programmatically. I…
alex2k8
  • 39,732
  • 56
  • 158
  • 214
10
votes
1 answer

Can I name a function signature?

I'm passing around a partially applied function. The full signature is: import Data.Map as Map -- Update the correct bin of the histogram based on the min value, bin width, -- the histogram stored as a map, and the actual value we are interested…
Tim Perry
  • 2,846
  • 1
  • 21
  • 36
10
votes
2 answers

Perl 6 multi methods never match expected signature

I have a class with two multi methods (multi submit). I call my multi like this: $perspective.submit(:message($message.content)); Which gets shipped off to my class: my $perspective-api =…
kawaii
  • 291
  • 1
  • 8
10
votes
2 answers

Why is throws part of the method signature

Why is throws on a method part of it's signature. It seems strange to include it. Here is a example where it is in the way. @Overide public void foo() { throw new UnsupportedOperationException(); } If anyone where to see this method from the…
Frozendragon
  • 1,669
  • 1
  • 24
  • 46
10
votes
1 answer

Is it possible to write a Rust macro that will expand into a function/method signature?

I would love to be able to something like the following: macro_rules! impl_a_method( ($obj:ident, $body:block) => ( fn a_method(foo: Foo, bar: Bar, baz: Baz) -> $obj $body ) ) // Implementation would look…
mindTree
  • 786
  • 7
  • 18
9
votes
3 answers

What does this signature mean (&) in PHP?

Consider: public function & get($name, $default = null) Why &?
user198729
  • 55,886
  • 102
  • 239
  • 342
8
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,004
  • 3
  • 10
  • 30
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
  • 657
  • 3
  • 18
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
  • 7,746
  • 1
  • 23
  • 29
1
2
3
13 14