Hi All,
Source : Johns mock exam
public static void main(
String args[] )
{
List<? extends Number> type = new ArrayList<Integer>(); // 1
for ( Integer n : type ) // 2
{
System.out.println(n); // 3
}
}
public <T> void seth(List<?> type) // 4
{
type.add("hi"); // 5
}
Output is Line 2 and Line 5 have compiler errors.
I understood line 5 but for line 2 this was the explanation
type in main() has to be referenced by a Number not an Integer. So the for in loop fails to compile.
Can anybody explain me the above line?
Thanks All