Method signatures

I know I’ve probably used this term a bunch in other blog posts but I don’t think I’ve ever explained what a method signature is.

In Xojo a “method signature” is the unique way Xojo identifies each method so it can know which method you are calling in your code.

So what does that include ?

First off it does NOT include the SCOPE. PRIVATE, PUBLIC, GLOBAL, and PROTECTED are scope modifiers – but they are not part of the signature of a method.

Attributes are also not part of the signature.

And, curiously enough, the return type is NOT part of the signature. While that determines where you can use the method (ie in an expression where a value is expected vs not) it is NOT part of the signature.

The signature includes only the name and parameter list.

It gets a LOT more confusing if your parameter lists have optional or default parameter values since the signature basically can be thought to be “variable” – but its still just the name and parameter list.

And if you ever get an error saying

There is more than one item with this name and it’s not clear to which this refers.

and the compiler has hilighted a method call then the likelihood is you have two signatures that can be treated the same and the compiler cannot figure out which one you really meant to use.

2 Replies to “Method signatures”

  1. Do you know what they chose not to include teh return type as part of the signature?

    many times for the years I’ve run into situations that would have been useful!

    1. I dont
      That decision was made so long ago (predating all the compiler engineers I knew – Mars, Aaron and Joe).
      Andrew made that decision ages ago and it has since lived on.
      But since Java also does not consider the return type as part of the signature its not completely foreign.
      This lets you have multiple overloaded methods and even lets subclasses override that parent class implementations with one that returns a compatible type (ie/ a subclass etc)

Comments are closed.