Java Code Examples for java.lang.invoke.MethodHandles#empty()
The following examples show how to use
java.lang.invoke.MethodHandles#empty() .
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: ConstantIdentityMHTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test void testEmpty() throws Throwable { MethodHandle cat = lookup().findVirtual(String.class, "concat", methodType(String.class, String.class)); assertEquals("xy", (String)cat.invoke("x","y")); MethodHandle mhEmpty = MethodHandles.empty(cat.type()); assertEquals(null, (String)mhEmpty.invoke("x","y")); }
Example 2
Source File: LoggerImpl.java From beautiful_logger with MIT License | 4 votes |
private static MethodHandle empty_void(MethodType methodType) { if (IS_JAVA_8) { return MethodHandles.dropArguments(NOP, 0, methodType.parameterList()); } return MethodHandles.empty(methodType); }
Example 3
Source File: LoopCombinatorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider = "iterateParameters") public static void testIterateParameters(MethodType it, MethodType in, MethodType bo, String msg) { boolean negative = !msg.isEmpty(); MethodHandle iterator = it == null ? null : MethodHandles.empty(it); MethodHandle init = in == null ? null : MethodHandles.empty(in); boolean caught = false; MethodHandle loop = null; try { loop = MethodHandles.iteratedLoop(iterator, init, MethodHandles.empty(bo)); } catch (Throwable t) { if (!negative) { throw t; } assertEqualsFIXME(msg, t.getMessage()); caught = true; } if (negative) { assertTrue(caught); } else { MethodType lt = loop.type(); if (it == null && in == null) { assertEquals(bo.dropParameterTypes(0, 1), lt); } else if (it == null) { if (in.parameterCount() == 0) { assertEquals(bo.dropParameterTypes(0, in.returnType() == void.class ? 1 : 2), lt); } else { assertEquals(methodType(bo.returnType(), in.parameterArray()), lt); } } else if (in == null) { assertEquals(methodType(bo.returnType(), it.parameterArray()), lt); } else if (it.parameterCount() > in.parameterCount()) { assertEquals(methodType(bo.returnType(), it.parameterArray()), lt); } else if (it.parameterCount() < in.parameterCount()) { assertEquals(methodType(bo.returnType(), in.parameterArray()), lt); } else { // both it, in present; with equal parameter list lengths assertEquals(it.parameterList(), lt.parameterList()); assertEquals(in.parameterList(), lt.parameterList()); assertEquals(bo.returnType(), lt.returnType()); } } }
Example 4
Source File: ConstantIdentityMHTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test @ExpectedExceptions(NullPointerException.class) void testEmptyNPE() { MethodHandle lenEmptyMH = MethodHandles.empty(null); }