Given the code fragment:
UnaryOperator
List
loanValues.stream()
.filter(lv -> lv >= 1500)
.map(lv -> uo1.apply(lv))
.forEach(s -> System.out.print(s + " "));
What is the result?
Given the code fragment:
UnaryOperator
List
loanValues.stream()
.filter(lv -> lv >= 1500)
.map(lv -> uo1.apply(lv))
.forEach(s -> System.out.print(s + " "));
What is the result?
The code will have a compilation error at the line where the `.map(lv -> uo1.apply(lv))` method is used. The map method expects a function that takes a Double and returns a value, but the UnaryOperator uo1 is defined to take an Integer and return an Integer. This type mismatch causes a compilation error.
A compilation errors at Line 2, because uo1.apply() takes an integer but in map() we are passing a double
D is the correct answer
Answer D is correct since .map(lv -> uo1.apply(lv)) line fails to compile as uo1 expects Integer, but Double is provided.
A compilation errors at Line 2 :The method map(Function<? super Double,? extends R>) in the type Stream<Double> is not applicable for the arguments (UnaryOperator<Integer>