File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes (generics) Understanding Joshua Bloch's java reloaded presentation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "(generics) Understanding Joshua Bloch Watch "(generics) Understanding Joshua Bloch New topic
Author

(generics) Understanding Joshua Bloch's java reloaded presentation

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

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 ]

    Regards,

    Pho
    Jim Yingst
    Wanderer
    Sheriff

    Joined: Jan 30, 2000
    Posts: 18671
    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.


    "I'm not back." - Bill Harding, Twister
    Pho Tek
    Ranch Hand

    Joined: Nov 05, 2000
    Posts: 761

    Got it. So wildcarding means any type expression that contains a ?.
    Jim Yingst
    Wanderer
    Sheriff

    Joined: Jan 30, 2000
    Posts: 18671
    Yup, exactly.
     
    Consider Paul's rocket mass heater.
     
    subject: (generics) Understanding Joshua Bloch's java reloaded presentation