My code is:
import java.util.*;
public class A {
public static void main(String[] args){
List<String> list = new ArrayList();
list.add("1"); //ok line 1
list.add(1); //error line 2
}
When I run this code Java gives me an error and I know why, but even when I only use line 1 the compiler warns me. Why do I get this warning? I don't understand what is the difference between my first example and this code:
import java.util.*;
public class A {
public static void main(String[] args){
List<String> list = new ArrayList<String>(); // <-- notice the second <String>
list.add("1"); //ok line 1
list.add(1); //error line 2
}
}