nerdexam
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)
  • A
    2% (1)
  • B
    5% (2)
  • C
    12% (5)
  • D
    81% (35)

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice