• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

(generics) Understanding Joshua Bloch's java reloaded presentation

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joshua Bloch PDF

On slide 20:

Don't confuse bounded wildcards with bounded type variables.

Bounded wildcards
void sell(Collection<? extends T> myLot);
- Major use: restrict input parameters
- Can use super

Bounded type variables
<T extends Number> T sum(List<T> x) { � }
- Restricts actual type parameter: Works for parameterized classes and methods
- Can't use super


What does he mean when he writes Can use super and Can't use super ?

My guess below; but I require your confirmation:

  • "Can use super" means that I can call #sell( Collection<T> c ).
  • "Can't use super" means that #sum( List<Number> ) is disallowed


  • Am I correct ?
    [ January 15, 2008: Message edited by: Pho Tek ]
     
    Jim Yingst
    Wanderer
    Sheriff
    Posts: 18671
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    No, he's talking about whether or not you can use the actual keyword "super" as part of the code with each of those types. For example with a wildcard, you can have <?>, <? extends X>, <? super Y> or <? extends X super Y> (where X and Y are some classes or interfaces; could be anything). With a bounded type variable though, you can't use "super" at all. You can only have things like <T> or <T extends X>. That's what he's saying.
     
    Pho Tek
    Ranch Hand
    Posts: 782
    Chrome Python Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Got it. So wildcarding means any type expression that contains a ?.
     
    Jim Yingst
    Wanderer
    Sheriff
    Posts: 18671
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yup, exactly.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic