Oracle
1Z0-819 · Question #54
Which code fragment compiles?
The correct answer is D. D. Comparator<Integer> comparator = new Comparator<>() { public int compare(Integer i, Integer j) { return i.compareTo(j); } }. See the full explanation below for the reasoning.
Question
Which code fragment compiles?
Options
- AA. Comparator comparator = new Comparator<?>() { public int compare(Integer i, Integer j) { return i.compareTo(j); } };
- BB. var comparator = new Comparator<>() { public int compare(Integer i, Integer j) { return i.compareTo(j); } };
- CC. Comparator<> comparator = new Comparator<Integer>() { public int compare(Integer i, Integer j) { return i.compareTo(j); } };
- DD. Comparator<Integer> comparator = new Comparator<>() { public int compare(Integer i, Integer j) { return i.compareTo(j); } };
How the community answered
(46 responses)- A9% (4)
- B17% (8)
- C4% (2)
- D70% (32)
Community Discussion
No community discussion yet for this question.