4

I 'm going through a code and found the following method declaration.

public void onItemClick(AdapterView<?> parent, View v, int position, long id)

What does <?> mean here?

Thank you.

Priya Kathir
  • 263
  • 1
  • 6
  • 2
    The term you are looking for is "generics". I have updated the tags appropriately. See the related posts. –  Dec 07 '11 at 04:18
  • 1
    http://stackoverflow.com/questions/1844770/what-does-list-mean-in-java-generics , http://stackoverflow.com/questions/6777936/what-does-map-mean-in-java , http://stackoverflow.com/questions/3009745/what-does-the-question-mark-in-java-generics-type-parameter-mean , http://stackoverflow.com/questions/1149964/java-generic-method-question –  Dec 07 '11 at 04:19

1 Answers1

6

AdapterView is a generic class. It takes another data type as a parameter, and its operation is then customized towards that type, in a way. Normally, you'll declare an AdapterView something like

AdapterView<String> avs = new AdapterView<String>(...);

This refers to an AdapterView customized for Strings.

Now, given all that: the <?> means that this method will accept an AdapterView regardless of the class it's customized for. It's a wildcard type specifier.

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186