Program:
-----------
public static void main(
String[] args) {
{
List names = new ArrayList();
names.add("Rams");
names.add("Shanker");
List numbers = new ArrayList();
numbers.add(new Integer("1"));
numbers.add(new Integer("2"));
printDet(numbers,"mumbers");
printDet(names,"names");
}
public static void printDet(List list,String type){
Class myclass;
if(type.equals("numbers")){
myclass = Integer.class;
}
else if(type.equals("names")){
myclass = String.class;
}
for(int i=0;i<list.size();i++){
System.out.println((myclass)list.get(i));
}
}
output:
--------
Error: 'myclass' is not resolved to a type...
Can anybody explain why this is not working?
Is there anyother way of coding to compile this example successfully?
Thanks,