Java语法<?>说明 [英] Java syntax <?> explanation
问题描述
你好,我在网格视图
gridview.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView< ; $> parent,View v,int position,long id){
Toast.makeText(HelloGridView.this,+ position,Toast.LENGTH_SHORT).show();
}
});
这个< ?> (空间添加为stackoverflow不允许没有空格)指示/做?
< ? >是泛型类型的通配符,这意味着AdapterView的泛型类型可以是任何东西。
更具体地说,在这种情况下,该方法的参数可能会收到AdapterView绝对是任何泛型类型。请注意,如果您想限制泛型类型,您可以这样做:
AdapterView<扩展myClass)
这将通用类型限制为myClass或扩展myClass的任何类型。
请注意:
AdapterView<?>和AdapterView <?扩展对象>
完全相同。
你可以找到附加信息在通配符部分
Hi I came across a code in documentation of android in Grid view for the following code.
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(HelloGridView.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
In this what does the < ?> (space added as stackoverflow didn't allow without space) indicate/do?
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<? extends myClass)
This limits the generic type to myClass or anything that extends myClass.
Just as a note:
AdapterView <?> and AdapterView<? extends Object>
Are identical.
You can find additional information here in the wildcards section
这篇关于Java语法<?>说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!