Oracle
1Z0-819 · Question #114
Given: public class Main { public static void main(String[] args) { List<String> arrayList = new ArrayList<>(); arrayList.add("hello"); arrayList.add("world"); print(1); } private static void…
The correct answer is D. @SafeVarargs on the print method. See the full explanation below for the reasoning.
Question
Given:
public class Main {
public static void main(String[] args) {
List<String> arrayList = new ArrayList<>();
arrayList.add("hello");
arrayList.add("world");
print(1);
}
private static void print(List<String>... args) {
for (List<String> str : args) {
System.out.println(str);
}
}
}
Which annotation should be used to remove warnings from compilation?
Options
- A@SuppressWarnings("unchecked") on the main and print methods
- B@SuppressWarnings("rawtypes") on the main and @SafeVarargs on the print method
- C@SuppressWarnings("rawtypes") on the main and print methods
- D@SafeVarargs on the print method
How the community answered
(43 responses)- A2% (1)
- B5% (2)
- C12% (5)
- D81% (35)
Community Discussion
No community discussion yet for this question.