本文整理匯總了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);
}