java 对 ArrayAdapter 的未经检查的调用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4204706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unchecked call to ArrayAdapter
提问by xil3
I get the following warning when I instantiate my ArrayAdapter (compiles fine):
当我实例化我的 ArrayAdapter(编译正常)时,我收到以下警告:
warning: [unchecked] unchecked call to ArrayAdapter(android.content.Context,int,java.util.List<T>) as a member of the raw type android.widget.ArrayAdapter
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(CFAMain.this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
And here's the problem line:
这是问题所在:
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(CFAMain.this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
Anyone have any ideas as to why it's giving me this warning?
任何人都知道为什么它给我这个警告?
回答by Cristian
That's because ArrayAdapter
expects you to specify which type of object it will manipulate. So, in order to avoid those warnings just do:
那是因为ArrayAdapter
期望您指定它将操作的对象类型。因此,为了避免这些警告,只需执行以下操作:
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(CFAMain.this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);