Java Language Specification - Generics

Discussion in 'Java' started by E11, Oct 6, 2005.

  1. E11

    E11 Guest

    Hi,

    In section 4.5 of the Java Language Specification, there is such a
    paragraph:

    There are a few things that i don't quite understand.

    1. What is the meaning of "Xi <: Bi[A1 := X1, ..., An := Xn]"? i know
    that Xi <: Bi means that Xi is a sub-class of Bi, but what does it mean
    to have all that stuff in square parentheses after Bi?

    2. What is capture conversion? It is explained in §5.1.10, but i don't
    quite understand the explanation. Anyone able to do it in more layman
    terms?



    Thanks in Advance,
    Edwin
     
    E11, Oct 6, 2005
    #1
    1. Advertising

  2. E11 wrote:
    > Hi,
    >
    > In section 4.5 of the Java Language Specification, there is such a
    > paragraph:
    >
    >
    >
    > There are a few things that i don't quite understand.
    >
    > 1. What is the meaning of "Xi <: Bi[A1 := X1, ..., An := Xn]"? i know
    > that Xi <: Bi means that Xi is a sub-class of Bi, but what does it mean
    > to have all that stuff in square parentheses after Bi?


    It's described in the first paragraph. It means that the actual type
    arguments are substituted in place of the formal type variables in order
    to determine the actual bounds.

    >
    > 2. What is capture conversion? It is explained in §5.1.10, but i don't
    > quite understand the explanation. Anyone able to do it in more layman
    > terms?


    As best I understand the text, it is describing a conversion wherein
    wildcard type arguments are interpreted in terms of the bounds of the
    corresponding type parameters.

    The whole section you quoted seems to be defining the semantics of
    bounded and unbounded wildcard type variables. That is, the details
    governing the fact that you can assign a List<Integer> to a variable of
    type List<? extends Number>, but you can't assign a List<String> to that
    variable.

    --
    John Bollinger
     
    John C. Bollinger, Oct 7, 2005
    #2
    1. Advertising

  3. E11

    E11 Guest

    Hi John, your last paragraph went some way in helping me understand
    those symbols... its a little clearer now.

    John C. Bollinger wrote:
    >
    > > 1. What is the meaning of "Xi <: Bi[A1 := X1, ..., An := Xn]"? i know
    > > that Xi <: Bi means that Xi is a sub-class of Bi, but what does it mean
    > > to have all that stuff in square parentheses after Bi?

    >
    > It's described in the first paragraph. It means that the actual type
    > arguments are substituted in place of the formal type variables in order
    > to determine the actual bounds.


    So, what it means is...
    Ai, i = 1..n are the formal type parameters of C
    Bi is the declared bound of Ai, i = 1..n (hmm... but is it upper bound
    or lower bound?)
    If we do a substitution of Ai for Xi, i = 1..n,
    then it is necessary that Xi is a sub-type of Bi, i = 1..n, or a
    compile time error occurs.

    hmm... does that make sense?

    i think the issue i face regarding "for each actual type argument Xi, i
    = 1..n, Xi <: Bi[A1 := X1, ..., An := Xn]", is due to the scope of "[A1
    := X1, ..., An := Xn]" with respect to the scope of the universal
    qualifier.

    In other words, if we use parentheses to represent scope, does the
    above mean
    "for each actual type argument Xi, i = 1..n, (Xi <: Bi[A1 := X1, ...,
    An := Xn])"
    or
    "(for each actual type argument Xi, i = 1..n, Xi <: Bi)[A1 := X1, ...,
    An := Xn]"
    ?



    Thanks and Regards,
    Edwin
     
    E11, Oct 7, 2005
    #3
  4. E11 wrote:
    > Hi John, your last paragraph went some way in helping me understand
    > those symbols... its a little clearer now.


    I hope it's both clear and correct. I'm feeling my way on this one --
    formal type theory is not one of my areas of expertise.

    > John C. Bollinger wrote:
    >
    >>>1. What is the meaning of "Xi <: Bi[A1 := X1, ..., An := Xn]"? i know
    >>>that Xi <: Bi means that Xi is a sub-class of Bi, but what does it mean
    >>>to have all that stuff in square parentheses after Bi?

    >>
    >>It's described in the first paragraph. It means that the actual type
    >>arguments are substituted in place of the formal type variables in order
    >>to determine the actual bounds.

    >
    >
    > So, what it means is...
    > Ai, i = 1..n are the formal type parameters of C
    > Bi is the declared bound of Ai, i = 1..n (hmm... but is it upper bound
    > or lower bound?)


    Either one. You can't have both for any single type parameter (more's
    the pity). See also below.

    > If we do a substitution of Ai for Xi, i = 1..n,
    > then it is necessary that Xi is a sub-type of Bi, i = 1..n, or a
    > compile time error occurs.
    >
    > hmm... does that make sense?


    I think "subtype" isn't quite the right term, because the Bi aren't
    types, they're *bounds* (i.e. "extends Comparable<Foo>" rather than just
    Comparable<Foo>). Nevertheless, I think you've pretty much got it.

    > i think the issue i face regarding "for each actual type argument Xi, i
    > = 1..n, Xi <: Bi[A1 := X1, ..., An := Xn]", is due to the scope of "[A1
    > := X1, ..., An := Xn]" with respect to the scope of the universal
    > qualifier.
    >
    > In other words, if we use parentheses to represent scope, does the
    > above mean
    > "for each actual type argument Xi, i = 1..n, (Xi <: Bi[A1 := X1, ...,
    > An := Xn])"
    > or
    > "(for each actual type argument Xi, i = 1..n, Xi <: Bi)[A1 := X1, ...,
    > An := Xn]"
    > ?


    The first, I think; the second doesn't make any sense to me. You must
    evaluate each bound in light of all of the actual type parameters, and
    in each case you must perform that evaluation before you can evaluate
    the <: operation.

    --
    John Bollinger
     
    John C. Bollinger, Oct 8, 2005
    #4
  5. E11

    E11 Guest

    John C. Bollinger wrote:
    >
    > > "for each actual type argument Xi, i = 1..n, (Xi <: Bi[A1 := X1, ...,
    > > An := Xn])"

    >
    > The first, I think; the second doesn't make any sense to me. You must
    > evaluate each bound in light of all of the actual type parameters, and
    > in each case you must perform that evaluation before you can evaluate
    > the <: operation.


    That's actually kinda confusing... so the above actually means

    X1 <: B1[A1 := X1, ..., An := Xn], and ..., and
    Xn <: Bn[A1 := Xn, ..., An := Xn]

    As in, why do we have to repeat the [...] for every Xi and Bi?

    Why is it not sufficient to say

    X1 <: B1[A1 := X1], and ..., and Xn <: Bn[An := Xn]
    or say
    X1 <: B1, and ..., and Xn <: Bn, [A1 := Xi, ..., An := Xn]
    ?

    i sort of vaguely recall seeing such a notation before when i was in
    college, i think it was in a programming languages, or a computability
    theory module... should have tried to stay awake then...



    Thanks and Regards,
    Edwin
     
    E11, Oct 8, 2005
    #5
  6. E11 wrote:
    > John C. Bollinger wrote:
    >
    >>>"for each actual type argument Xi, i = 1..n, (Xi <: Bi[A1 := X1, ...,
    >>>An := Xn])"

    >>
    >>The first, I think; the second doesn't make any sense to me. You must
    >>evaluate each bound in light of all of the actual type parameters, and
    >>in each case you must perform that evaluation before you can evaluate
    >>the <: operation.

    >
    >
    > That's actually kinda confusing... so the above actually means
    >
    > X1 <: B1[A1 := X1, ..., An := Xn], and ..., and
    > Xn <: Bn[A1 := Xn, ..., An := Xn]


    That's my reading, yes.

    > As in, why do we have to repeat the [...] for every Xi and Bi?


    Because each bound needs to be interpreted in light of all the actual
    type parameters. This may not be evident in simple type expressions,
    but it will rear its head in some complex type expressions. (If you
    feel a breeze, it's from all the hand waving I'm doing.)

    --
    John Bollinger
     
    John C. Bollinger, Oct 9, 2005
    #6
  7. E11

    E11 Guest

    John C. Bollinger wrote:
    >
    > That's my reading, yes.
    >
    > > As in, why do we have to repeat the [...] for every Xi and Bi?

    >
    > Because each bound needs to be interpreted in light of all the actual
    > type parameters. This may not be evident in simple type expressions,
    > but it will rear its head in some complex type expressions. (If you
    > feel a breeze, it's from all the hand waving I'm doing.)


    hmm... i really don't understand this point... sorry if its frustrating
    for you, but it is possible to use an example to illustrate this point?



    Many Thanks,
    Edwin
     
    E11, Oct 9, 2005
    #7
    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. Juergen Berchtel
    Replies:
    1
    Views:
    6,033
    John C. Bollinger
    May 20, 2005
  2. Matthew

    Java Language Specification

    Matthew, Jan 23, 2007, in forum: Java
    Replies:
    1
    Views:
    317
    Oliver Wong
    Jan 23, 2007
  3. Claudio Nieder
    Replies:
    4
    Views:
    709
  4. Soul
    Replies:
    0
    Views:
    532
  5. Tobia Conforto
    Replies:
    5
    Views:
    253
    Tobia Conforto
    Nov 10, 2012
Loading...

Share This Page