nerdexam
Oracle

1Z0-819 · Question #49

Assuming that Widget class has a getPrice method t is code does not compile: List widgets = List.of( new Widget("Basic Widget", 19.55), // line 1 new Widget("Enhanced Widget", 35.00), new…

The correct answer is A. Replace line 5 with widgetStream.filter(w -> ((Widget)w).getPrice() > 20.00). See the full explanation below for the reasoning.

Question

Assuming that Widget class has a getPrice method t is code does not compile: List widgets = List.of( new Widget("Basic Widget", 19.55), // line 1 new Widget("Enhanced Widget", 35.00), new Widget("Luxury Edition Widget", 55.45)); Stream widgetStream = widgets.stream(); // line 4 widgetStream.filter(w -> w.getPrice() > 20.00) .forEach(System.out::print); // line 5 Which two statements, independently, would allow this code to compile? (Choose two.)

Options

  • AReplace line 5 with widgetStream.filter(w -> ((Widget)w).getPrice() > 20.00).
  • BReplace line 5 with List<Widget> widgetStream = widgets.stream();.
  • CReplace line 4 with Stream<Object> widgetStream = widgets.stream();.
  • DReplace line 4 with Stream<Widget> widgetStream = widgets.stream();.

How the community answered

(30 responses)
  • A
    80% (24)
  • B
    3% (1)
  • C
    10% (3)
  • D
    7% (2)

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice