This discussion is archived
9 Replies Latest reply: May 3, 2011 11:07 PM by EJP RSS

Generic method signatures

774879 Newbie
Currently Being Moderated
I've searched but can't find that a question I have has been asked (or answered). I apologize in advance if it has. Here is my question.

In Java Generics FAQ by Angelika Langer states in FAQ 802 ( [http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#FAQ802] ) "the type parameters of a generic method including the type parameter bounds are part of the method signature."

In FAQ 810, many examples are presented of method declarations, including generic ones, and their corresponding method signatures. For example,

<T> T method(T arg) has the following signature in the example:

<$T1_extends_Object>method($T1_extends_Object>)

It would seem to be intuitively clear that the type parameter and bounds would be part of the method signature but I can't seem to find such a stipulation/requirement of such in the Java Language Specification. Anybody know where it's stipulated in the JLS?

Best Regards
  • 1. Re: Generic method signatures
    796440 Guru
    Currently Being Moderated
    http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.12.2

    Good luck. It's not pleasant.
  • 2. Re: Generic method signatures
    774879 Newbie
    Currently Being Moderated
    This is embarrassing: I've already looked there (but only cursorily). I still don't see it. I was hoping someone would have drilled down in there to know where it could be at least inferred. Any ideas?
  • 3. Re: Generic method signatures
    796440 Guru
    Currently Being Moderated
    user13143654 wrote:
    This is embarrassing: I've already looked there (but only cursorily). I still don't see it. I was hoping someone would have drilled down in there to know where it could be at least inferred. Any ideas?
    "The first phase ([url http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#301185]§15.12.2.2) performs overload resolution..."

    [url http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#301185]§15.12.2.2, in turn describes how the types of the method signature are matched against the types of the actual arguments given by the caller, and whether those types are compatible.
  • 4. Re: Generic method signatures
    774879 Newbie
    Currently Being Moderated
    Yeah, I know. The title of the subsection is "Determining Method Signature," but then it never seems to expressly do that other than in some ephemeral wafting byproduct of overload resolution. I can't seem to find a specific spot in the subsection where I can say "OK, now I've got the method signature and now can proceed to ..." But I can't find anywhere else in the JLS where there would be a discussion of it.
  • 5. Re: Generic method signatures
    796440 Guru
    Currently Being Moderated
    user13143654 wrote:
    Yeah, I know. The title of the subsection is "Determining Method Signature," but then it never seems to expressly do that other than in some ephemeral wafting byproduct of overload resolution.
    I wouldn't call it "ephemeral" and "wafting." It's pretty specific. If you're looking for the $T1_extends_Object notation, you won't find it. That's not part of the spec.
    I can't seem to find a specific spot in the subsection where I can say "OK, now I've got the method signature and now can proceed to ..."
    Well, it goes on to Phase 3, and then on to 15.12.2.5 Choosing the Most Specific Method. I'm not sure what you're looking for. It does describe in detail how we get from all the methods in the universe, to which type's methods we'll be considering to which signatures could match to which one is the best match. I don't know what else you're looking for.

    If you're looking for somebody to digest, translate, and simplify all that for you, good luck, but it ain't gonna be me. :-)

    If you have specific questions about smaller pieces of it I (or somebody else) might be able to help out. At the moment though, your question is rather vague.

    Edited by: jverd on May 3, 2011 1:48 PM
  • 6. Re: Generic method signatures
    774879 Newbie
    Currently Being Moderated
    I understand "$T1_extends_Object" is certainly an artifact of the compiler Langer was using, but there still never seems to be a clear spot in the algorithm where it is really clear that the type parameters and their bounds are an integral part of a generic method's signature. I was just hoping someone in these environs knew where in that mess that the fact that they are could be at least inferred. I didn't want to have to wade through the whole thing and have that fact be like the conclusion of a mathematical conjecture that took years to prove before it became a celebrated theorem.

    Vague? Is this any clearer?

    Where in the JLS can it be seen (or inferred) that the type parameters and their bounds are an integral part of a generic method's signature such that a compiler writer would know that this generic method:

    <T> T method(T arg)

    would have a signature that could be expressed like this:

    <$T1_extends_Object>method($T1_extends_Object>



    Edited by: user13143654 on May 3, 2011 1:57 PM
  • 7. Re: Generic method signatures
    796440 Guru
    Currently Being Moderated
    user13143654 wrote:
    I understand "$T1_extends_Object" is certainly an artifact of the compiler Langer was using, but there still never seems to be a clear spot in the algorithm where it is really clear that the type parameters and their bounds are an integral part of a generic method's signature. I was just hoping someone in these environs knew where in that mess that the fact that they are could be at least inferred. I didn't want to have to wade through the whole thing and have that fact be like the conclusion of a mathematical conjecture that took years to prove before it became a celebrated theorem.
    We don't always get what we want.

    As you can quite clearly see, it does not say, "the type parameters and their bounds are an integral part of a generic method's signature." How does it affect you that it doesn't say that? Since it doesn't say that explicitly, and since nobody, so far at least, is taking the time to walk you through the exact clauses in that section of the spec from which that conclusion can be drawn, do you doubt its veracity? Will you code and debug differently now, being uncertain if that statement is in fact true?
  • 8. Re: Generic method signatures
    796440 Guru
    Currently Being Moderated
    user13143654 wrote:
    Where in the JLS can it be seen (or inferred) that the type parameters and their bounds are an integral part of a generic method's signature such that a compiler writer would know that this generic method:

    <T> T method(T arg)

    would have a signature that could be expressed like this:

    <$T1_extends_Object>method($T1_extends_Object>
    In the sections I already indicated. However, it's neither stated that directly, nor is it an inference. It is simply a conclusion.

    Those sections tell us how we know a method is applicable, in terms of method's parameters and type parameters. How does one not conclude from that that "type parameters are an integral part of a method's signature"?

    Note also that "signature" is defined here: http://java.sun.com/docs/books/jls/third_edition/html/classes.html#38649
  • 9. Re: Generic method signatures
    EJP Guru
    Currently Being Moderated
    It would seem to be intuitively clear that the type parameter and bounds would be part of the method signature but I can't seem to find such a stipulation/requirement of such in the Java Language Specification.
    and
    Where in the JLS can it be seen (or inferred) that the type parameters and their bounds are an integral part of a generic method's signature
    JLS #8.4.2, third bullet point. Note the part about 'the bounds of corresponding type variables'.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points