Unknown user
Unknown user

Reputation: 45331

Understanding syntax in Java

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?

Upvotes: 1

Views: 655

Answers (2)

bobah
bobah

Reputation: 18864

the generics/wildcards tutorial explains this syntax

Upvotes: 0

Joachim Sauer
Joachim Sauer

Reputation: 308269

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.

Upvotes: 9

Related Questions