HI,
import java.util.*;
public class
test {
public static void main(
String args[])
{
List<Integer> l=new ArrayList<Integer>();
new test().hi(new ArrayList<List<? extends Number>>());
}
public void hi(List<List<? extends Number>> a)
{
a.add(new ArrayList<Integer>());
}
}
I have a doubt regarding generics , How can the above code compile
because it adds an element to <? extends Number>
import java.util.*;
public class test
{
public static void main(String args[])
{
List<Integer> l=new ArrayList<Integer>();
l.add(5);
List<Integer> q=new ArrayList<Integer>();
l.add(1);
List<List<? extends Number>> a=new ArrayList<List<? extends Number>>();
a.add(l);
a.add(q);
for(List<? extends Number> o:a)
System.out.println(o);
}
}
This example is same as the above one as you can see it adds the eleement
Please explain why does it add when it says ? (wildcards) are not supposed to make an type be added