本文整理匯總了Java中java.lang.invoke.MethodHandles.whileLoop方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodHandles.whileLoop方法的具體用法?Java MethodHandles.whileLoop怎麽用?Java MethodHandles.whileLoop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.invoke.MethodHandles
的用法示例。
在下文中一共展示了MethodHandles.whileLoop方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testWhileLoopNoIteration
import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Test
public static void testWhileLoopNoIteration() throws Throwable {
// a while loop that never executes its body because the predicate evaluates to false immediately
MethodHandle loop = MethodHandles.whileLoop(While.MH_initString, While.MH_predString, While.MH_stepString);
assertEquals(While.MT_string, loop.type());
assertEquals("a", loop.invoke());
}
示例2: testWhileBadInit
import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Test
public static void testWhileBadInit() throws Throwable {
boolean caught = false;
try {
While w = new While();
MethodHandle loop = MethodHandles.whileLoop(MethodHandles.empty(methodType(void.class, char.class)),
While.MH_voidPred.bindTo(w),
While.MH_voidBody.bindTo(w));
} catch (IllegalArgumentException iae) {
assertEquals("loop initializer must match: (char)void != (int)void", iae.getMessage());
caught = true;
}
assertTrue(caught);
}
示例3: testWhileVoidInit
import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Test
public static void testWhileVoidInit() throws Throwable {
While w = new While();
int v = 5;
MethodHandle loop = MethodHandles.whileLoop(While.MH_voidInit.bindTo(w), While.MH_voidPred.bindTo(w),
While.MH_voidBody.bindTo(w));
assertEquals(While.MT_void, loop.type());
loop.invoke(v);
assertEquals(v, w.i);
}
示例4: testWhileNullArgs
import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Test(dataProvider = "nullArgs", expectedExceptions = NullPointerException.class)
public static void testWhileNullArgs(MethodHandle pred, MethodHandle body) {
MethodHandles.whileLoop(null, pred, body);
}
示例5: testDoWhileNullArgs
import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Test(dataProvider = "nullArgs", expectedExceptions = NullPointerException.class)
public static void testDoWhileNullArgs(MethodHandle body, MethodHandle pred) {
MethodHandles.whileLoop(null, body, pred);
}