Hi
Please tell why i am not getting runtime error for this
class A
{
public static void main(
String... args)
{
List<Integer> l=new ArrayList<Integer>();
Collection<?>l1=new ArrayList<String>();//line 1
l.add(1);
l.add(2);
l1=l;//line 2
Integer s=l.get(0);
System.out.println("The values are : "+s+" "+l1);
}
}
At line i have created a reference of collection l1 which is able to refer to any type and i have created an arraylist of String
And at line 2 i am assigning arraylist of Integer to l1.
At run time what is going on?
How the JVM is doing all these things.
i know Generics are used for compile time.
And i won't check at run.
But i am not able understand what is going on?
please tell me