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


Java MethodHandle.asVarargsCollector方法代码示例

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


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

示例1: CatchExceptionTest

import java.lang.invoke.MethodHandle; //导入方法依赖的package包/类
public CatchExceptionTest(TestCase testCase, final boolean isVararg, final int argsCount,
        final int catchDrops) {
    this.testCase = testCase;
    this.dropped = catchDrops;
    MethodHandle thrower = testCase.thrower;
    int throwerLen = thrower.type().parameterCount();
    List<Class<?>> classes;
    int extra = Math.max(0, argsCount - throwerLen);
    classes = getThrowerParams(isVararg, extra);
    this.argsCount = throwerLen + classes.size();
    thrower = Helper.addTrailingArgs(thrower, this.argsCount, classes);
    if (isVararg && argsCount > throwerLen) {
        MethodType mt = thrower.type();
        Class<?> lastParam = mt.parameterType(mt.parameterCount() - 1);
        thrower = thrower.asVarargsCollector(lastParam);
    }
    this.thrower = thrower;
    this.dropped = Math.min(this.argsCount, catchDrops);
    catcher = testCase.getCatcher(getCatcherParams());
    nargs = Math.max(2, this.argsCount);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:CatchExceptionTest.java

示例2: CatchExceptionTest

import java.lang.invoke.MethodHandle; //导入方法依赖的package包/类
public CatchExceptionTest(TestCase testCase, final boolean isVararg,
                          final int argsCount, final int catchDrops) {
    this.testCase = testCase;
    this.dropped = catchDrops;
    MethodHandle thrower = testCase.thrower;
    int throwerLen = thrower.type().parameterCount();
    List<Class<?>> classes;
    int extra = Math.max(0, argsCount - throwerLen);
    classes = getThrowerParams(isVararg, extra);
    this.argsCount = throwerLen + classes.size();
    thrower = Helper.addTrailingArgs(thrower, this.argsCount, classes);
    if (isVararg && argsCount > throwerLen) {
        MethodType mt = thrower.type();
        Class<?> lastParam = mt.parameterType(mt.parameterCount() - 1);
        thrower = thrower.asVarargsCollector(lastParam);
    }
    this.thrower = thrower;
    this.dropped = Math.min(this.argsCount, catchDrops);
    catcher = testCase.getCatcher(getCatcherParams());
    nargs = Math.max(2, this.argsCount);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:CatchExceptionTest.java

示例3: dropReceiver

import java.lang.invoke.MethodHandle; //导入方法依赖的package包/类
private static MethodHandle dropReceiver(final MethodHandle mh, final Class<?> receiverClass) {
    MethodHandle newHandle = MethodHandles.dropArguments(mh, 0, receiverClass);
    // NOTE: this is a workaround for the fact that dropArguments doesn't preserve vararg collector state.
    if(mh.isVarargsCollector() && !newHandle.isVarargsCollector()) {
        final MethodType type = mh.type();
        newHandle = newHandle.asVarargsCollector(type.parameterType(type.parameterCount() - 1));
    }
    return newHandle;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:StaticClassIntrospector.java

示例4: testVarargsCollector0

import java.lang.invoke.MethodHandle; //导入方法依赖的package包/类
public void testVarargsCollector0() throws Throwable {
    if (CAN_SKIP_WORKING)  return;
    startTest("varargsCollector");
    MethodHandle vac0 = PRIVATE.findStatic(MethodHandlesTest.class, "called",
                           MethodType.methodType(Object.class, String.class, Object[].class));
    vac0 = vac0.bindTo("vac");
    MethodHandle vac = vac0.asVarargsCollector(Object[].class);
    testConvert(true, vac.asType(MethodType.genericMethodType(0)), null, "vac");
    testConvert(true, vac.asType(MethodType.genericMethodType(0)), null, "vac");
    for (Class<?> at : new Class<?>[] { Object.class, String.class, Integer.class }) {
        testConvert(true, vac.asType(MethodType.genericMethodType(1)), null, "vac", at);
        testConvert(true, vac.asType(MethodType.genericMethodType(2)), null, "vac", at, at);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:MethodHandlesTest.java


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