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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 05:18:19  来源:igfitidea点击:

unchecked call to ArrayAdapter

javaandroidwarningscompiler-warnings

提问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 ArrayAdapterexpects 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);