Share

RECODER

Subscribe

TypeArgumentDeclaration vs. TypeArgument?

You are viewing a single message from this topic. View all messages.

  1. 2009-11-02 10:24:01 UTC

    Hej!

    TypeArgumentDeclaration may be a not so good naming, but what's done is done ;-) Anyway, it is a type argument that occurs in source code. Example: In
    List<? extends Number>
    the "? extends Number" is a TypeArgumentDeclaration.

    A TypeParameterDeclaration is always part of another declaration, namely either of a MethodDeclaration or a TypeDeclaration. Thus, a TypeArgumentDeclaration is kind of "applied" to TypeParameterDeclarations, just like arguments to a method are "applied" to its formal parameters.
    More examples:
    interface ListOfLists<T extends List> extends java.util.List<T> { ... } - "T extends List" is a TypeParameterDeclaration, whereas "T" is a TypeArgumentDeclaration.
    public <T> T foo(T t) { return t; } - the first "T" is a TypeParameterDeclaration of the method. It determines its (static!) return type based on the static type of the argument passed to the parameter "t". Or, the method could even be invoked explicitly: this&lt;String&gt;.foo(null); will have a static type of "String". If the type argument "String" is not passed, then something called "type inference" is performed.

    Regarding your note 1:
    I cannot see how a type parameter could be declared in a method's formal parameter list (they can only be referenced)

    I think some of the source code you provided got lost in the formatting. Please post it again if you have further question.

    Best regards, Tobias

< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.