本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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);
}
}