Two Laptop Bag
The moose likes Beginning Java and the fly likes Generics - what does it mean Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Generics - what does it mean "? super T"?" Watch "Generics - what does it mean "? super T"?" New topic
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Generics - what does it mean "? super T"?
 
Similar Threads
Question about generics
need help about generics
public static <T extends Comparable<? super T>> void sort(List<T> list)
Good Reference on Generics
Generics - Why does it work?