Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the meaning of the question mark inside the angle brackets: <? extends java.lang.Comparable>

In App Engine, according to the JavaDoc, the getTypeRank method has this signature:

public static int getTypeRank(java.lang.Class<? extends java.lang.Comparable> datastoreType)

In the method signature there is a question mark inside the angle brackets:

<? extends java.lang.Comparable>

What does it signify?

like image 532
cheese Avatar asked Feb 28 '10 08:02

cheese


People also ask

What do angle brackets in Java mean?

Angle Bracket in Java is used to define Generics. It means that the angle bracket takes a generic type, say T, in the definition and any class as a parameter during the calling. The idea is to allow type (Integer, String, … etc and user-defined types) to be a parameter to methods, classes, and interfaces.

What do angle brackets mean in coding?

What Does Angle Bracket Mean? The angle bracket (< or >), which is also called an “inequality sign” for its use in mathematics, is a kind of sideways caret that can be used to include tags or pieces of code. This ASCII set of characters is common in web design and other types of coding projects.

What does empty <> mean in Java?

The Java programming language distinguishes between null and empty strings. An empty string is a string instance of zero length, whereas a null string has no value at all. An empty string is represented as "" . It is a character sequence of zero characters. A null string is represented by null .

How do you use angle brackets?

Usage of angle bracketsIn some languages, a double set of angle brackets may be used in place of quotation marks to contain quotes. In English, they may be used informally to insert asides, indicate speech in a foreign language, or to mention a website, but all of these uses are rare even in informal writing.


2 Answers

? essentially indicates a wildcard. <? extends java.lang.Comparable> means "any type that extends java.lang.Comparable (or Comparable itself) can be used here".

like image 200
Gabe Avatar answered Sep 27 '22 21:09

Gabe


It's called bounded wildcard

<? extends Comparable> is an example of a bounded wildcard. The ? stands for an unknown type, just like the wildcards we saw earlier. However, in this case, we know that this unknown type is in fact a subtype of Comparable. (Note: It could be Comparableitself, or some subclass; it need not literally extend Comparable.)

More details you find here

like image 27
stacker Avatar answered Sep 27 '22 20:09

stacker