there is no right answer because of raw type in UnaryOperator declaration
A. Failed
error: incompatible types: incompatible parameter types in lambda expression
UnaryOperator u = (int i)->i*2;
^
B. failed
i is type of Object because of raw type
bad operand types for binary operator '*'
C. failed
we can not skip the parenthesis in single parametr lambda
D. failed
i is type of Object because of raw type
bad operand types for binary operator '*'
and return with semicolons
None correct answer:
but if the options have a Typed in declaration this two options are valid:
B. UnaryOperator<Integer> u = (var i) -> i * 2;
D. UnaryOperator<Integer> u = i -> i * 2;
UnaryOperator<Integer> u = (int i) -> i * 2. => invalid, lamba only accepts wrapper clases not primitives
C. UnaryOperator<Integer> u = var i -> { return i * 2; }; // bad sintax for var i cannot contain (var i)
that is correct
Tested. All are wrong. Because all left side in answers are the same we should find correct expression on right side. Let say that on left side in all answers we have "UnaryOperator<Integer>" instead of "UnaryOperator". That make sense because left side is the same in all answers. In that case only B is valid.
There's no answer here. As first of all: All of these UnaryOperators are of type UnaryOperator<Object> so there's not a single one valid.
Secondly you can't modify a List created with List.of() so it will throw a unsupportedOperationException
The correct answer is `A. UnaryOperator u = (int i) -> i * 2;`. This line of code creates a `UnaryOperator` object that takes an `int` as input and returns the result of multiplying the input by 2.
Option B is incorrect because the `var` keyword cannot be used in a lambda expression. Option C is incorrect because the syntax for a lambda expression with a single parameter does not allow the use of the `var` keyword. Option D is incorrect because the lambda expression is missing a closing brace.
There is no correct answer here. The specified UnaryOperators can only store objects. If they had types(<Integer> for instance), then A & D with some bit of syntax correction could have worked
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ASPushkin
6 months, 2 weeks agomendjijet
12 months agod7bb0b2
1 year agod7bb0b2
1 year agoOmnisumem
1 year, 4 months ago[Removed]
1 year, 5 months agoStavok
1 year, 6 months agotmuralimanohar
1 year, 7 months agoMSEng
1 year, 7 months agoStavok
1 year, 8 months agoxuancat
1 year, 8 months ago