I am getting warning in my ListActivity
. The warning I am getting is shown below
Class is a raw type. References to generic type Class<T> should be
parameterized
It is not creating any problems, but I would like to know why I am getting this warning and how to suppress it. See line which written within asterisks.
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();
}
}
}
Class is generic, if you don't care for the warning you have two choices use @SuppressWarnings("rawtypes")
or my preference use the <?>
(that is a wildcard capture) like this
Class<?> ourclass = Class.forName("com.app1."+cheese);
You can use @SuppressWarnings("rawtypes","unchecked")
. You can also make the code
Class<?> ourclass= Class.forName("com.app1."+cheese);
to get rid of the warning. Now, you don't have to use @SuppressWarnings("rawtypes")
. Compiler expects all the generic types to be parameterized
To ignore the warning "Class is a raw type...." do the following inside eclipse*:
When you reopen eclipse, these specific warnings should no longer be listed.
*For this example solution I'm using Eclipse IDE for Java Developers - Version: Mars.2 Release (4.5.2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With