java.lang.invoke.MethodHandles#empty ( )源码实例Demo

下面列出了java.lang.invoke.MethodHandles#empty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk9   文件: ConstantIdentityMHTest.java
@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"));
}
 
源代码2 项目: beautiful_logger   文件: LoggerImpl.java
private static MethodHandle empty_void(MethodType methodType) {
  if (IS_JAVA_8) {
    return MethodHandles.dropArguments(NOP, 0, methodType.parameterList());  
  }
  return MethodHandles.empty(methodType);
}
 
源代码3 项目: openjdk-jdk9   文件: LoopCombinatorTest.java
@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());
        }
    }
}
 
源代码4 项目: openjdk-jdk9   文件: ConstantIdentityMHTest.java
@Test
@ExpectedExceptions(NullPointerException.class)
void testEmptyNPE() {
    MethodHandle lenEmptyMH = MethodHandles.empty(null);
}