The
temp collection is not typed, so the
temp.add() method runs successfully even for objects of "incorrect" type.
The only case of exception is when during the call to ar collection elements will be casted to Integer type (explicit or implicit cast). There is no such a situation in this example, therefore the loop over collection will be successful.
To avoid adding the 'incorrect' values to the collection, it will be enough to use the verification presenting like this one:
List temp = Collections.checkedList(ar, Integer.class);
Ввійдіть щоб вподобати
Ввійдіть щоб прокоментувати