• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

(generics) Understanding Joshua Bloch's java reloaded presentation

 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
     
    Wanderer
    Posts: 18671
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Python Chrome Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Got it. So wildcarding means any type expression that contains a ?.
     
    Jim Yingst
    Wanderer
    Posts: 18671
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yup, exactly.
    reply
      Bookmark Topic Watch Topic
    • New Topic