What are the difference between Descriptor and Signature

Discussion in 'Java' started by bearice@gmail.com, Feb 15, 2008.

  1. Guest

    When looking at java class file. many thing has two attribute:
    Descriptor and Signature. at most time they looks the same. So who can
    tell what are the differences between them? Thank you.
    , Feb 15, 2008
    #1
    1. Advertising

  2. Lew Guest

    wrote:
    > When looking at java class file. many thing has two attribute:
    > Descriptor and Signature. at most time they looks the same. So who can
    > tell what are the differences between them? Thank you.


    The term "descriptor" (lower-case "d") in a Java context usually refers to a
    text file (often XML) that contains configuration information for a program or
    a system, such as for a Web app. Literally it just means "something that
    describes."

    The "signature" (lower-case "s") of a method is the formal pattern of a
    method, that is the argument types and their order, the return type and the
    exception types.

    --
    Lew
    Lew, Feb 15, 2008
    #2
    1. Advertising

  3. Tom McGlynn Guest

    On Feb 15, 1:56 am, "" <> wrote:
    > When looking at java class file. many thing has two attribute:
    > Descriptor and Signature. at most time they looks the same. So who can
    > tell what are the differences between them? Thank you.


    While descriptor has a lot of possible meanings, if you are comparing
    it with signatures, you may be thinking of descriptors in the context
    of usage
    in the JVM (e.g., http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html).

    If so, then the signature of a method is the specification of the
    types of the formal parameters of the method. I don't know that there
    is any canonical representation of the signature of a method beyond
    the method name and argument list as used in a Java program.
    Generally the signature is something that the compiler worries about
    but isn't used so much at run time. The descriptor includes the return
    type of the method, which is not part of the signature, and has a very
    specific string representation for all of this that is used within the
    class files.


    Regards,
    Tom McGlynn
    Tom McGlynn, Feb 15, 2008
    #3
  4. Tom McGlynn Guest

    On Feb 15, 8:22 am, Lew <> wrote:
    > wrote:
    > > When looking at java class file. many thing has two attribute:
    > > Descriptor and Signature. at most time they looks the same. So who can
    > > tell what are the differences between them? Thank you.

    >
    > The term "descriptor" (lower-case "d") in a Java context usually refers to a
    > text file (often XML) that contains configuration information for a program or
    > a system, such as for a Web app. Literally it just means "something that
    > describes."
    >
    > The "signature" (lower-case "s") of a method is the formal pattern of a
    > method, that is the argument types and their order, the return type and the
    > exception types.
    >
    > --
    > Lew


    I believe the signature includes neither the return type nor the
    exceptions thrown, just the method name and the types of the
    parameters. This is discussed in the JLS (in 8.4.3 in the 3rd
    edition). E.g.,
    "Two methods have the same signature if they have the same name and
    argument types."
    See <http://java.sun.com/docs/books/jls/third_edition/html/
    classes.html#8.4.2>

    Regards,
    Tom McGlynn
    Tom McGlynn, Feb 15, 2008
    #4
  5. wrote:
    > When looking at java class file. many thing has two attribute:
    > Descriptor and Signature. at most time they looks the same. So who can
    > tell what are the differences between them? Thank you.


    A method descriptor is the name followed by the formal parameter types
    followed by the return type. The signature is the same, but includes
    generic types.

    E.g.:
    Set.get(K k):
    Descriptor: put(Ljava/lang/Object;)Ljava/lang/Object;
    Signature: put(TK;)TV;

    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth
    Joshua Cranmer, Feb 15, 2008
    #5
  6. Lew Guest

    Tom McGlynn wrote:
    > On Feb 15, 8:22 am, Lew <> wrote:
    >> wrote:
    >>> When looking at java class file. many thing has two attribute:
    >>> Descriptor and Signature. at most time they looks the same. So who can
    >>> tell what are the differences between them? Thank you.

    >> The term "descriptor" (lower-case "d") in a Java context usually refers to a
    >> text file (often XML) that contains configuration information for a program or
    >> a system, such as for a Web app. Literally it just means "something that
    >> describes."
    >>
    >> The "signature" (lower-case "s") of a method is the formal pattern of a
    >> method, that is the argument types and their order, the return type and the
    >> exception types.
    >>
    >> --
    >> Lew

    >
    > I believe the signature includes neither the return type nor the
    > exceptions thrown, just the method name and the types of the
    > parameters. This is discussed in the JLS (in 8.4.3 in the 3rd
    > edition). E.g.,
    > "Two methods have the same signature if they have the same name and
    > argument types."
    > See <http://java.sun.com/docs/books/jls/third_edition/html/
    > classes.html#8.4.2>


    You are correct. However, it is still useful to think of return type and
    exception types as part of the signature. If you don't respect those, you can
    get compiler errors. So informally I think of the signature as including
    those factors.

    For example, if you declare two methods in a class with the same signature,
    it's a compiler error. If you declare two methods that differ only in
    (non-covariant) return type, you get an error. If you add checked exceptions
    to a method override, you get an error. The mental dodge of pretending that
    exceptions and return types are part of the signature helps me keep that straight.

    Still, it is pretending. You are right about the definition.

    --
    Lew
    Lew, Feb 16, 2008
    #6
  7. On 2008-02-16 02:50 +0100, Lew allegedly wrote:
    > Tom McGlynn wrote:
    >> On Feb 15, 8:22 am, Lew <> wrote:
    >>> wrote:
    >>>> When looking at java class file. many thing has two attribute:
    >>>> Descriptor and Signature. at most time they looks the same. So who can
    >>>> tell what are the differences between them? Thank you.
    >>> The term "descriptor" (lower-case "d") in a Java context usually
    >>> refers to a
    >>> text file (often XML) that contains configuration information for a
    >>> program or
    >>> a system, such as for a Web app. Literally it just means "something
    >>> that
    >>> describes."
    >>>
    >>> The "signature" (lower-case "s") of a method is the formal pattern of a
    >>> method, that is the argument types and their order, the return type
    >>> and the
    >>> exception types.
    >>>
    >>> --
    >>> Lew

    >>
    >> I believe the signature includes neither the return type nor the
    >> exceptions thrown, just the method name and the types of the
    >> parameters. This is discussed in the JLS (in 8.4.3 in the 3rd
    >> edition). E.g.,
    >> "Two methods have the same signature if they have the same name and
    >> argument types."
    >> See <http://java.sun.com/docs/books/jls/third_edition/html/
    >> classes.html#8.4.2>

    >
    > You are correct. However, it is still useful to think of return type
    > and exception types as part of the signature. If you don't respect
    > those, you can get compiler errors. So informally I think of the
    > signature as including those factors.
    >
    > For example, if you declare two methods in a class with the same
    > signature, it's a compiler error. If you declare two methods that
    > differ only in (non-covariant) return type, you get an error. If you
    > add checked exceptions to a method override, you get an error. The
    > mental dodge of pretending that exceptions and return types are part of
    > the signature helps me keep that straight.


    The examples you give tend to prove the opposite of what you seem to
    intend, rather. If the return type and the exceptions clause were part
    of the signature, then two methods which differ only in return type
    would have a _different_ signature, and thus it wouldn't be an error.

    df.
    Daniele Futtorovic, Feb 16, 2008
    #7
  8. Lew Guest

    Daniele Futtorovic wrote:
    > The examples you give tend to prove the opposite of what you seem to
    > intend, rather. If the return type and the exceptions clause were part
    > of the signature, then two methods which differ only in return type
    > would have a _different_ signature, and thus it wouldn't be an error.


    An excellent point. Actually, the JVM's definition of "descriptors" matches
    what I was saying before. Thus am I corrected and have learned something new.

    --
    Lew
    Lew, Feb 16, 2008
    #8
  9. On 2008-02-16 04:40 +0100, Lew allegedly wrote:
    > Actually, the JVM's definition of "descriptors"
    > matches what I was saying before.


    And so the loose ends are joined together and it seems like we have
    answered the original question in a rather exhaustive manner. Not bad
    for a runaway OP. :x)
    Daniele Futtorovic, Feb 16, 2008
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JJBW
    Replies:
    1
    Views:
    10,147
    Joerg Jooss
    Apr 24, 2004
  2. jakk
    Replies:
    4
    Views:
    12,139
  3. Santa
    Replies:
    1
    Views:
    1,074
    Mark A. Odell
    Jul 17, 2003
  4. Gustavo Narea
    Replies:
    14
    Views:
    865
    Gustavo Narea
    Feb 16, 2009
  5. PerlFAQ Server
    Replies:
    0
    Views:
    355
    PerlFAQ Server
    Jan 6, 2011
Loading...

Share This Page