Java Code Examples for java.lang.invoke.MethodHandles#zero()
The following examples show how to use
java.lang.invoke.MethodHandles#zero() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoopCombinatorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test public static void testCountedLoopVoidInit() throws Throwable { MethodHandle fit5 = MethodHandles.constant(int.class, 5); for (int i = 0; i < 8; i++) { MethodHandle zero = MethodHandles.zero(void.class); MethodHandle init = fit5; MethodHandle body = Counted.MH_printHello; boolean useNull = (i & 1) != 0, addInitArg = (i & 2) != 0, addBodyArg = (i & 4) != 0; if (useNull) zero = null; if (addInitArg) init = MethodHandles.dropArguments(init, 0, int.class); if (addBodyArg) body = MethodHandles.dropArguments(body, 1, int.class); System.out.println("testCountedLoopVoidInit i="+i+" : "+Arrays.asList(init, zero, body)); MethodHandle loop = MethodHandles.countedLoop(init, zero, body); MethodType expectedType = Counted.MT_countedPrinting; if (addInitArg || addBodyArg) expectedType = expectedType.insertParameterTypes(0, int.class); assertEquals(expectedType, loop.type()); if (addInitArg || addBodyArg) loop.invoke(99); else loop.invoke(); } }
Example 2
Source File: LoopCombinatorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@DataProvider static Object[][] countedLoopNegativeData() { MethodHandle dummy = MethodHandles.zero(void.class); MethodHandle one = MethodHandles.constant(int.class, 1); MethodHandle oneString = MethodHandles.dropArguments(one, 0, String.class); MethodHandle oneDouble = MethodHandles.dropArguments(one, 0, double.class); return new Object[][]{ {dummy, one, dummy, dummy, String.format("start/end must return int %s, %s", dummy, one)}, {one, dummy, dummy, dummy, String.format("start/end must return int %s, %s", one, dummy)}, {oneString, oneDouble, dummy, dummy, String.format("start and end parameter types must match: %s != %s", oneString.type(), oneDouble.type())}, {oneString, oneString, dummy, dummy, String.format("start/end and init parameter types must match: %s != %s", oneString.type(), dummy.type())}, {one, one, null, dummy, String.format("actual and expected body signatures must match: %s != %s", dummy.type(), dummy.type().appendParameterTypes(int.class))} }; }
Example 3
Source File: ConstantIdentityMHTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test @ExpectedExceptions(NullPointerException.class) public void testZeroNPE() { MethodHandle mh = MethodHandles.zero(null); }