Agreed that no answer correct.
Old style List without generic diamond keeps Objects inside.
It will be compile error : incompatible types, Object -> Integer throws exception.
------
But this code works :
for(Object i : x) {
System.out.println(i);
}
No answer correct, code not comiple for this for(Integer i : x){} //expected objetct not integer.
but if the line are modified like this:
var x = new ArrayList<Integer>(); then throw
thown:
java.lang.ClassCastException: class java.lang.Float cannot be cast to class java.lang.Integer
No answer as for loop is expecting objects and not Integer.
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ASPushkin
5 months agod7bb0b2
6 months, 3 weeks agoOmnisumem
9 months, 3 weeks agodilleman
10 months agobelal97
1 year agoSamps
6 months, 4 weeks agoKiraguJohn
1 year ago