當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。