1

I would like your help in understanding what this syntax means:

class Node<K extends Comparable<? super K>, V>

What does the ? stands for?

And isn't there one < missing?

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Unknown user
  • 44,551
  • 16
  • 38
  • 42
  • 1
    See also [Can someone explain what does super T> mean and when should it be used and how this construction should cooperate with and extends T>?](http://stackoverflow.com/questions/2310449/can-someone-explain-what-does-super-t-mean-and-when-should-it-be-used-and-how/) – Péter Török Apr 20 '11 at 10:02
  • 2
    A very good resource about Java generics is Angelika Langer's Java Generics FAQ: http://www.angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html – Jesper Apr 20 '11 at 11:16

2 Answers2

9

The ? stands for "some unknown type". In this specific case it's ? super K which means "some unknown type that's a base type of K (i.e. "super class of" or "interface implemented by") .

And no, there's no < missing: you have two < and two >, they match up.

Practically it means that Node has two type arguments: K which probably represents a key, which must be Comparable to itself and V which probably represents a value.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
0

the generics/wildcards tutorial explains this syntax

bobah
  • 18,364
  • 2
  • 37
  • 70
  • 1
    I downvoted this because answers that are **just** a single link [are not considered to be good answers](http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers). – Joachim Sauer Apr 20 '11 at 10:28
  • @Joachim Sauer - right, cut-n-paste is better than the link to the exact answer on the technology owner's site ... – bobah Apr 20 '11 at 10:32
  • 1
    Who's talking about cut-and-paste? Did you read the question I linked to? The issue has been discussed. – Joachim Sauer Apr 20 '11 at 10:34
  • @Joachim Sauer - the author of the question is confused with the syntax of wildcards in generics that is precisely what the article behind the link I gave explains. I did read the question you gave a link to, and I do believe that being a robot is not the best attitude to develop in yourself. In this particular case a single link IS a good answer. – bobah Apr 20 '11 at 10:38
  • @bobah: and it's great if you helped, my personal opinion is something different, but that's no problem. A down-vote is not a personal attack. Obviously at least 2 people think that your answer is good, so you got the upvotes. I don't see the problem. – Joachim Sauer Apr 20 '11 at 10:41