JDK-8206941 : Release Note: New Collection.toArray(IntFunction) Default Method
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 11
  • Priority: P3
  • Status: Closed
  • Resolution: Delivered
  • Submitted: 2018-07-09
  • Updated: 2018-10-18
  • Resolved: 2018-07-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11
11Resolved
Description
A new default method `toArray(IntFunction)` has been added to the `java.util.Collection` interface. This method allows the collection's elements to be transferred to a newly created array of a desired runtime type. The new method is an overload of the existing `toArray(T[])` method that takes an array instance as an argument. The addition of the overloaded method creates a minor source incompatibility. Previously, code of the form `coll.toArray(null)` would always resolve to the existing `toArray` method. With the new overloaded method, this code is now ambiguous and will result in a compile-time error. (This is only a source incompatibility. Existing binaries are unaffected.) The ambiguous code should be changed to cast `null` to the desired array type, for example, `toArray((Object[])null)` or some other array type. Note that passing `null` to either `toArray` method is specified to throw `NullPointerException`.