我在收到警告ListActivity
.我得到的警告如下所示
Class is a raw type. References to generic type Class
它没有造成任何问题,但我想知道为什么我会得到这个警告以及如何抑制它.查看用星号写的行.
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(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(); } } }
Elliott Fris.. 15
类是通用的,如果你不关心警告你有两个选择使用@SuppressWarnings("rawtypes")
或我的偏好使用>
(这是一个通配符捕获)像这样
Class> ourclass = Class.forName("com.app1."+cheese);
Keerthivasan.. 6
你可以用@SuppressWarnings("rawtypes","unchecked")
.你也可以制作代码
Class> ourclass= Class.forName("com.app1."+cheese);
摆脱警告.现在,您不必使用@SuppressWarnings("rawtypes")
.编译器期望参数化所有泛型类型