[Home]MethodSignature

Robo Home | Changes | Preferences | AllPages

Two methods (or functions) are said to have the same "signature" if they have the same name and the same number of arguments with the same type in the same order. For instance these two functions have the same signature and can't exist inside the same class?:
void goTo(Point2D destination) {
   // all work and no play
}

void goTo(Point2D point) {
  // diffferent names on the argument doesn't matter
}
While these three functions have different signatures and can coexist inside a class.
void goTo(Point2D destination) {
}

void moveTo(Point2D destination) {
}

void goTo(double x, double y) {
}
Filling in the body of the third function there it might look like this:
void goTo(double x, double y) {
    goTo(new Point2D.Double(x, y));
}
Which gives the user of the class two choices. But the programmer of the class would just have to maintain the first function.

-- PEZ


Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited May 9, 2003 20:29 EST by PEZ (diff)
Search: