Something I live with for long but I didn't ever understood..
The question is the comment :
import java.util.ArrayList;
import java.util.List;
public class Test {
public static class Test1 {
public List<String> getStrings(){
List<String> s = new ArrayList();
s.add("test1");
return s;
}
}
public static class Test2<PARAM> {
public List<String> getStrings(){
List<String> s = new ArrayList();
s.add("test2");
return s;}
}
public static void main(String[] args) {
Test1 test1 = new Test1();
Test2 test2 = new Test2();
for (String string : test1.getStrings()) {
System.out.println(string);
}
// Why do I need this cast (List<String>) ?
for (String string : (List<String>)test2.getStrings()) {
System.out.println(string);
}
}
}
So why do I need the cast (List) ?
Franck