当前位置: 首页>>代码示例>>Java>>正文


Java MethodHandles.zero方法代码示例

本文整理汇总了Java中java.lang.invoke.MethodHandles.zero方法的典型用法代码示例。如果您正苦于以下问题:Java MethodHandles.zero方法的具体用法?Java MethodHandles.zero怎么用?Java MethodHandles.zero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.invoke.MethodHandles的用法示例。


在下文中一共展示了MethodHandles.zero方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCountedLoopVoidInit

import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@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();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:LoopCombinatorTest.java

示例2: countedLoopNegativeData

import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@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))}
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:LoopCombinatorTest.java

示例3: testZeroNPE

import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test
@ExpectedExceptions(NullPointerException.class)
public void testZeroNPE() {
    MethodHandle mh = MethodHandles.zero(null);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:ConstantIdentityMHTest.java


注:本文中的java.lang.invoke.MethodHandles.zero方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。