| Author |
(generics) Understanding Joshua Bloch's java reloaded presentation
|
Pho Tek
Ranch Hand
Joined: Nov 05, 2000
Posts: 757
|
|
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: 18670
|
|
|
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: 757
|
|
|
Got it. So wildcarding means any type expression that contains a ?.
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
|
Yup, exactly.
|
 |
 |
|
|
subject: (generics) Understanding Joshua Bloch's java reloaded presentation
|
|
|