Given the code fragment:
Which can replace line 11?
Given the code fragment:
Which can replace line 11?
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.
A is valid if it looks like this UnaryOperator<Integer> uo = (var x) -> (x * 3);
Tested: A is closest.
A is close to correct
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
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