Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 140

Given the code fragment:

Which can replace line 11?

    Correct Answer: A

    The correct option is A. Lambda expressions in Java can use `var` which lets the compiler infer the type of the parameter. Option A correctly defines the UnaryOperator using `var`. Options B, C, and D either use incorrect syntax or have issues related to type specification or missing braces and return statements.

Discussion
KiraguJohnOption: A

A is valid if it looks like this UnaryOperator<Integer> uo = (var x) -> (x * 3);

OmnisumemOption: A

Tested: A is closest.

StavokOption: A

A is close to correct

ASPushkinOption: A

raw type UnaryOperator uo = (var x)->(x*3); is actually UnaryOperator<Object> we have : x*3 Object*3 - error A. is Ok B. UnaryOperator uo = (int x)->(x*3); MyClass.java:9: error: incompatible types: incompatible parameter types in lambda expression UnaryOperator<Integer> uo = (int x)->(x*3); C. UnaryOperator<Integer> uo = var x->(return x*3); Fail skip parentheses D UnaryOperator<Integer> uo = x->{return x*3;}; Fail terminator(;) is missing

d7bb0b2Option: A

a IS CORRECT; B is incorrect (primitives types cannot pass to lambda as parameter ONLY wrapper type) C bad sintax D bad sintax if return then { ; } must be