Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics - what does it mean "? super T"?

 
Mateus Lucio
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it means T or a superclass of T.
 
Mateus Lucio
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic