| Author |
Generics - what does it mean "? super T"?
|
Mateus Lucio
Ranch Hand
Joined: Jul 27, 2006
Posts: 57
|
|
Hi folks! I understood what <? extends T> means that ? is subtype of T, in other words ? extends or implements T, but what about the super? does it mean that ? is supertype of T??? I really didnt catch that!!! I'd appreciate if you guys explained it to me! thanks in advance!!
|
Studying ...
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
|
Yes, it means T or a superclass of T.
|
 |
Mateus Lucio
Ranch Hand
Joined: Jul 27, 2006
Posts: 57
|
|
By superclass you mean only extention (extends)? or it works for interfaces too? by the way, if its not asking too much could give me an exemple of a situation where I'd take advantage of this?
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
Yes it also works for superinterfaces. Here is an example of using the lower bounded wildcard. [ November 08, 2006: Message edited by: Keith Lynn ]
|
 |
Mateus Lucio
Ranch Hand
Joined: Jul 27, 2006
Posts: 57
|
|
I see! ... thank you very much! I understand it, now I'll write and run some code to master it (or be as close as possible) Thanks again!
|
 |
zero Corner
Greenhorn
Joined: Nov 23, 2009
Posts: 4
|
|
i am totally new in the Generic type in java, i don't really get what does the ? mean
public static <T extends Comparable<? super T>> void bubbleSort(T[] a, int n)
1)what does <T extends Comparable<? super T>> really mean? declaring the Generic T for the compiler to recognize it?
2) what does ? really for?
thank you in advance...
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Zero Corner, you have been warned about your name twice before. This is your last warning. Change it to something appropriate or your account will be closed.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Generics - what does it mean "? super T"?
|
|
|