Java OCA OCP Practice Question 2336

Question

Which method declaration can be inserted at (1) so that the program compiles without warnings?

public class Main {
  public static void main(String[] args) {
    List raw = new ArrayList();
    raw.add("2007");
    raw.add(2008);/*from   www .  j a  va2 s.co  m*/
    raw.add("2009");
    justDoIt(raw);
  }
  // (1) INSERT METHOD DECLARATION HERE.
}

Select the one correct answer.

(a) static void justDoIt(List<Integer> lst) { }
(b) static void justDoIt(List<?> lst) { }
(c) static <T> void justDoIt(List<T> lst) { }
(d) None of the above.


(b)

Note

Passing a raw list to either a list of Integers or to a list of type parameter T is not type-safe.




PreviousNext

Related