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