exam questions

Exam 1z0-819 All Questions

View all questions & answers for the 1z0-819 exam

Exam 1z0-819 topic 1 question 72 discussion

Actual exam question from Oracle's 1z0-819
Question #: 72
Topic #: 1
[All 1z0-819 Questions]

Given the code fragment:



Which can replace line 2?

  • A. UnaryOperator u = (int i) -> i * 2;
  • B. UnaryOperator u = (var i) -> (i * 2);
  • C. UnaryOperator u = var i -> { return i * 2; };
  • D. UnaryOperator u = i -> { return i * 2);
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
ASPushkin
6 months, 2 weeks ago
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
upvoted 1 times
...
mendjijet
12 months ago
Selected Answer: B
B is ok but notice that list is immutable
upvoted 1 times
...
d7bb0b2
1 year ago
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
upvoted 1 times
d7bb0b2
1 year ago
UnaryOperator<Integer> u = (Integer i) -> i * 2; OR THIS
upvoted 1 times
...
...
Omnisumem
1 year, 4 months ago
Selected Answer: B
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.
upvoted 2 times
...
[Removed]
1 year, 5 months ago
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
upvoted 1 times
...
Stavok
1 year, 6 months ago
Selected Answer: A
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.
upvoted 1 times
...
tmuralimanohar
1 year, 7 months ago
Answer: none of the above. list is immutable, hence throws unsupportedOperation exception
upvoted 1 times
...
MSEng
1 year, 7 months ago
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
upvoted 2 times
...
Stavok
1 year, 8 months ago
Selected Answer: B
B is Correct
upvoted 2 times
...
xuancat
1 year, 8 months ago
Selected Answer: B
B is correct
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
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.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago