60 626
Assignments Done
97,8%
Successfully Done
In April 2018

Answer to Question #60063 in Java | JSP | JSF for MB Knudsen

Question #60063
Which of the following methods will compile without error?

public int add(List<? extends Number> list) {
int sum = 0;
for (Integer i : list) sum += i;
return sum;
}

public int add(List<? super Integer> list) {
int sum = 0;
for (Integer i : list) sum += i;
return sum;
}

public int add(List<? extends Integer> list) {
int sum = 0;
for (Integer i : list) sum += i;
return sum;
}

public int add(List<?> list) {
int sum = 0;
for (Integer i : list) sum += i;
return sum;
}
Expert's answer
public int add(List<? extends Integer> list) {
int sum = 0;
for (Integer i : list) sum += i;
return sum;
}
Because only in this method is a valid class cast

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions