small query regarding generics
Hi,
I am trying to run a small Generics program in Eclipse. My problem is that when I try to compile the below program, i get the following warning message - "Type safety: The expression of type List needs unchecked conversion to conform to List<String>Demo.java"
The warning is showing at line 25 which is the setC() method.
When I change the setC() method as -
publicvoid setC(List<String> c){
this.list = c;
}
the warning disappears.
Can anyone tell mewhy am I not getting this warning for getC() method where again I am not using generic parameter for List return type of getC().
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
publicclass Demo{
List<String> c =new ArrayList<String>();
staticvoid iterate(Collection<String> c){
for (String s : c)
System.out.println(s);
}
publicstaticvoid main(String args[]){
List<String> l =new ArrayList<String>();
l.add("Ashsih");
l.add("Abrol");
iterate(l);
}
public List getC(){
return c;
}
publicvoid setC(List c){
this.c = c;
}
}

