What is a method signature anyone?

Discussion in 'Java' started by curious user, Sep 3, 2003.

  1. curious user

    curious user Guest

    I've tried asking jeeves.

    Is it the pattern of formal parameters for a method?
     
    curious user, Sep 3, 2003
    #1
    1. Advertisements

  2. curious user

    Ike Guest

    yes
     
    Ike, Sep 3, 2003
    #2
    1. Advertisements

  3. curious user

    VisionSet Guest

    It is everything in the method declaration req'd to override an exisiting
    method.

    For instance in a super class

    private void myMethod(String foo, int bar) {}

    For a subclass to override myMethod it must declare it as:

    x void myMethod(String myStringName, int myIntName) {}

    where x is a visibility modifier that is equal to the superclasses or more
    public, so in this case it can be anything, but if the superclass method was
    public then it could only be public.

    If you did not obey this and still used the method name myMethod, then the
    compiler would complain.

    If the parameters were different or ordered differently, eg (int myInt,
    String myString)
    Then this would be treated as a different method, this is legal, but would
    not be overriding the original. Hence this is still part of the signature.
     
    VisionSet, Sep 3, 2003
    #3
  4. curious user

    delusion Guest

    thankyou
     
    delusion, Sep 3, 2003
    #4
  5. curious user

    Roedy Green Guest

    yes. It is also a shorthand that Java uses internally in the class
    file to describe it. See http://mindprod.com/jgloss/signature.html
     
    Roedy Green, Sep 3, 2003
    #5
  6. You may find Google more useful: http://www.google.com
    Search for "java method signature".
    Third entry is "Calling java methods" on Sun's site, which should help.

    Steve
     
    Steve Horsley, Sep 3, 2003
    #6
  7. curious user

    Digital Puer Guest



    Your definition says:
    "Java has a way of compactly encoding the types of each parameter and
    the return type on a given method. This string is called the
    method's signature."

    This is different from C and C++, right? In those languages, a
    signature does not include the return type.
     
    Digital Puer, Sep 4, 2003
    #7
  8. curious user

    Peter Gal Guest

    Java Language Spec (2nd edition) 8.4.2 Method Signature:
    The signature of a method consists of the name of the method and the
    number and types of formal parameters to the methdod. A class may not
    declare two methods with the same signature, or a compile-time error occurs:

    abstract class Point
    {
    int x, y;
    abstract void move(int dx, int dy);
    void move(int dx, int dy) { x += dx; y += dy; } // error
    }

    causes a compile-time error "move(int,int) is already defined in Point"

    Peter G.
     
    Peter Gal, Sep 4, 2003
    #8
  9. curious user

    Roedy Green Guest

    Obviously C++ compilers have to be aware of return types when dealing
    with methods, no different from Java. Both languages allow no
    mechanism to have two different methods differing only in return type.

    If there is a difference, it is just a terminology
    convention. Java folk include the return type when they mean
    signature. You are telling me C++ folk mean just the parameters,
    probably because that is the only part relevant in matching up which
    method to use.
     
    Roedy Green, Sep 4, 2003
    #9
  10. curious user

    Seebs Guest

    Why did you do this silly thing, instead of reading a FAQ, or trying
    Google?

    -s
     
    Seebs, Sep 7, 2003
    #10
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.