1 /* |
1 /* |
2 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
1024 MethodHandle longsToString = publicLookup() |
1024 MethodHandle longsToString = publicLookup() |
1025 .findStatic(Arrays.class, "toString", methodType(String.class, long[].class)) |
1025 .findStatic(Arrays.class, "toString", methodType(String.class, long[].class)) |
1026 .asCollector(long[].class, 1); |
1026 .asCollector(long[].class, 1); |
1027 assertEquals("[123]", (String) longsToString.invokeExact((long)123)); |
1027 assertEquals("[123]", (String) longsToString.invokeExact((long)123)); |
1028 * }</pre></blockquote> |
1028 * }</pre></blockquote> |
|
1029 * <p> |
|
1030 * <em>Note:</em> The resulting adapter is never a {@linkplain MethodHandle#asVarargsCollector |
|
1031 * variable-arity method handle}, even if the original target method handle was. |
1029 * @param arrayType often {@code Object[]}, the type of the array argument which will collect the arguments |
1032 * @param arrayType often {@code Object[]}, the type of the array argument which will collect the arguments |
1030 * @param arrayLength the number of arguments to collect into a new array argument |
1033 * @param arrayLength the number of arguments to collect into a new array argument |
1031 * @return a new method handle which collects some trailing argument |
1034 * @return a new method handle which collects some trailing argument |
1032 * into an array, before calling the original method handle |
1035 * into an array, before calling the original method handle |
1033 * @throws NullPointerException if {@code arrayType} is a null reference |
1036 * @throws NullPointerException if {@code arrayType} is a null reference |
1065 swWrite4.invoke('P', 'Q', 'R', 'S', 0, 4); |
1068 swWrite4.invoke('P', 'Q', 'R', 'S', 0, 4); |
1066 assertEquals("BCPQRS", swr.toString()); |
1069 assertEquals("BCPQRS", swr.toString()); |
1067 swWrite4.invoke('W', 'X', 'Y', 'Z', 3, 1); |
1070 swWrite4.invoke('W', 'X', 'Y', 'Z', 3, 1); |
1068 assertEquals("BCPQRSZ", swr.toString()); |
1071 assertEquals("BCPQRSZ", swr.toString()); |
1069 * }</pre></blockquote> |
1072 * }</pre></blockquote> |
|
1073 * <p> |
|
1074 * <em>Note:</em> The resulting adapter is never a {@linkplain MethodHandle#asVarargsCollector |
|
1075 * variable-arity method handle}, even if the original target method handle was. |
1070 * @param collectArgPos the zero-based position in the parameter list at which to start collecting. |
1076 * @param collectArgPos the zero-based position in the parameter list at which to start collecting. |
1071 * @param arrayType often {@code Object[]}, the type of the array argument which will collect the arguments |
1077 * @param arrayType often {@code Object[]}, the type of the array argument which will collect the arguments |
1072 * @param arrayLength the number of arguments to collect into a new array argument |
1078 * @param arrayLength the number of arguments to collect into a new array argument |
1073 * @return a new method handle which collects some arguments |
1079 * @return a new method handle which collects some arguments |
1074 * into an array, before calling the original method handle |
1080 * into an array, before calling the original method handle |
1354 * What the target eventually returns is returned unchanged by the bound handle. |
1360 * What the target eventually returns is returned unchanged by the bound handle. |
1355 * <p> |
1361 * <p> |
1356 * The reference {@code x} must be convertible to the first parameter |
1362 * The reference {@code x} must be convertible to the first parameter |
1357 * type of the target. |
1363 * type of the target. |
1358 * <p> |
1364 * <p> |
1359 * (<em>Note:</em> Because method handles are immutable, the target method handle |
1365 * <em>Note:</em> Because method handles are immutable, the target method handle |
1360 * retains its original type and behavior.) |
1366 * retains its original type and behavior. |
|
1367 * <p> |
|
1368 * <em>Note:</em> The resulting adapter is never a {@linkplain MethodHandle#asVarargsCollector |
|
1369 * variable-arity method handle}, even if the original target method handle was. |
1361 * @param x the value to bind to the first argument of the target |
1370 * @param x the value to bind to the first argument of the target |
1362 * @return a new method handle which prepends the given value to the incoming |
1371 * @return a new method handle which prepends the given value to the incoming |
1363 * argument list, before calling the original method handle |
1372 * argument list, before calling the original method handle |
1364 * @throws IllegalArgumentException if the target does not have a |
1373 * @throws IllegalArgumentException if the target does not have a |
1365 * leading parameter type that is a reference type |
1374 * leading parameter type that is a reference type |