Java OCA OCP Practice Question 1601

Question

Rewrite this lambda using a constructor reference:

n -> new ArrayList<>(n)
  • A. ArrayList::new;
  • B. ArrayList::new();
  • C. ArrayList::new(n);
  • D. ArrayList::new[n];


A.

Note

A constructor reference uses the new keyword where a method name would normally go in a method reference.

It can implicitly take zero or one parameters just like a method reference.

We have one parameter, which gets passed to the constructor.

Option A is correct.




PreviousNext

Related