gpt4 book ai didi

java - 为什么我收到警告 :Class is a raw type. References to generic type Class should be parameterized”?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:51:22 26 4
gpt4 key购买 nike

我在 ListActivity 中收到警告.我收到的警告如下所示

  • Class is a raw type. References to generic type Class<T> should be
    parameterized

它不会产生任何问题,但我想知道为什么我会收到此警告以及如何抑制它。请参阅星号内写的行。

public class Menu extends ListActivity {

String classes[]={"Second","example1","example2","example3","example4"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this,android.R.layout.simple_list_item_1,classes));
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese=classes[position];
try{
**Class ourclass= Class.forName("com.app1."+cheese);**
Intent ourintent= new Intent(Menu.this,ourclass);
startActivity(ourintent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}

最佳答案

类是通用的,如果您不关心警告,您有两个选择使用 @SuppressWarnings("rawtypes")或者我喜欢使用 <?> (这是一个 wildcard capture )像这样

Class<?> ourclass = Class.forName("com.app1."+cheese);

关于java - 为什么我收到警告 :Class is a raw type. References to generic type Class<T> should be parameterized”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20451096/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com