Java syntax <?> explanation

前端 未结 1 1281
孤独总比滥情好
孤独总比滥情好 2021-01-29 04:52

Hi I came across a code in documentation of android in Grid view for the following code.

gridview.setOnItemClickListener(new OnItemClickListener() {
        publ         


        
1条回答
  •  离开以前
    2021-01-29 05:19

    The < ? > is a wild card for the generic type, meaning the generic type for AdapterView can be anything at all.

    More specifically in this case the parameter on the method may receive an AdapterView with absolutely any generic type. As a note if you wanted to limit the generic type you could do:

    AdapterView

    This limits the generic type to myClass or anything that extends myClass.

    Just as a note:

     AdapterView  and AdapterView 
    

    Are identical.

    You can find additional information here in the wildcards section

    Java generics documentation

    0 讨论(0)
提交回复
热议问题