© Fu Cheng 2018
Fu ChengExploring Java 9https://doi.org/10.1007/978-1-4842-3330-6_9

9. Enhanced Method Handles

Fu Cheng
(1)
Auckland, New Zealand
 
The class java.lang.invoke.MethodHandles is enhanced in Java 9 to include more static methods for creating different kinds of method handles.

arrayConstructor

The method MethodHandle arrayConstructor (Class<?> arrayClass) returns a method handle to construct arrays of the specified type arrayClass. The sole argument of the created method handle is an int value that specifies the size of the array, while the return value is the array. In Listing 9-1, I create a method handle to construct int[] arrays. Then I create an array of size 3 using the MethodHandle.
@Test
public void testArrayConstructor() throws ...

Get Exploring Java 9: Build Modularized Applications in Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.