Java Reference
In-Depth Information
type
[]::new
Here,
type
specifies the type of object being created. For example, assuming the form of
MyClass
shown in the preceding example and given the
MyClassArrayCreator
interface
shown here:
the following creates an array of
MyClass
objects and gives each element an initial value:
Here, the call to
func(3)
causes a three-element array to be created. This example can be
generalized. Any functional interface that will be used to create an array must contain a
method that takes a single
int
parameter and returns a reference to the array of the speci-
fied size.
As a point of interest, you can create a generic functional interface that can be used
with other types of classes, as shown here:
For example, you could create an array of five
Thread
objects like this:
One last point: In the case of creating a constructor reference for a generic class, you
can specify the type parameter in the normal way, after the class name. For example, if
MyGenClass
is declared like this: