if List<Object>
contains List<Integer>
than it is perfect But how could java allows the test of List<Integer>
containing List<Object>
without throwing any compile-time error.
TestCase-1
Object obj = "one";
List<Object> objs = Arrays.<Object>asList("one", 2, 3.14, 4);
List<Integer> ints = Arrays.asList(2, 4);
assert objs.contains(obj); //Statement 1
assert objs.containsAll(ints); //Statement 2
assert !ints.contains(obj); //Statement 3
assert !ints.containsAll(objs); //Statement 4
In above case statement 3 & 4 compile & run Successfully.So my doubts are :
- How can Statement 3 & 4 be run as there should be a compile-time error?
- Is it an error or there is some reason for providing such a contradictory support ?