本文整理汇总了Java中java.lang.invoke.MethodHandles.doWhileLoop方法的典型用法代码示例。如果您正苦于以下问题:Java MethodHandles.doWhileLoop方法的具体用法?Java MethodHandles.doWhileLoop怎么用?Java MethodHandles.doWhileLoop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.invoke.MethodHandles
的用法示例。
在下文中一共展示了MethodHandles.doWhileLoop方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDoWhileBadInit
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test
public static void testDoWhileBadInit() throws Throwable {
boolean caught = false;
try {
While w = new While();
MethodHandle loop = MethodHandles.doWhileLoop(MethodHandles.empty(methodType(char.class)),
While.MH_voidBody.bindTo(w),
While.MH_voidPred.bindTo(w));
} catch (IllegalArgumentException iae) {
assertEquals("loop initializer must match: ()char != (int)void", iae.getMessage());
caught = true;
}
assertTrue(caught);
}
示例2: testWhileZip
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test
public static void testWhileZip() throws Throwable {
MethodHandle loop = MethodHandles.doWhileLoop(While.MH_zipInitZip, While.MH_zipStep, While.MH_zipPred);
assertEquals(While.MT_zip, loop.type());
List<String> a = Arrays.asList("a", "b", "c", "d");
List<String> b = Arrays.asList("e", "f", "g", "h");
List<String> zipped = Arrays.asList("a", "e", "b", "f", "c", "g", "d", "h");
assertEquals(zipped, (List<String>) loop.invoke(a.iterator(), b.iterator()));
}
示例3: testDoWhileVoidInit
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test
public static void testDoWhileVoidInit() throws Throwable {
While w = new While();
int v = 5;
MethodHandle loop = MethodHandles.doWhileLoop(While.MH_voidInit.bindTo(w), While.MH_voidBody.bindTo(w),
While.MH_voidPred.bindTo(w));
assertEquals(While.MT_void, loop.type());
loop.invoke(v);
assertEquals(v, w.i);
}