In the following code snippet:
List<Integer> ints = new ArrayList<Integer>();
ints.add(1);
ints.add(2);
List<? extends Number> nums1 = ints;
ints.add(3);
ints.add(4);
System.out.println("nums1 : " + nums1);
List<? super Number> nums2 = (List<? super Number>) nums1;
nums2.add(5.381);
nums2.add(6);
//ints.add(7.61762); // compilation error
System.out.println("nums2 : " + nums2);
System.out.println("ints : " + ints);
The List of Integer (ints here) is printed as : ints : [1, 2, 3, 4, 5.381, 6] So it seems that something is wrong here ?
Actual O/P :
nums1 : [1, 2, 3, 4]
nums2 : [1, 2, 3, 4, 5.381, 6]
ints : [1, 2, 3, 4, 5.381, 6] <-- Why 5.381 is fine in List