本文整理汇总了Java中java.lang.invoke.MethodHandles.tryFinally方法的典型用法代码示例。如果您正苦于以下问题:Java MethodHandles.tryFinally方法的具体用法?Java MethodHandles.tryFinally怎么用?Java MethodHandles.tryFinally使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.invoke.MethodHandles
的用法示例。
在下文中一共展示了MethodHandles.tryFinally方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTryFinally
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
void testTryFinally(MethodHandle target, MethodHandle cleanup, String input, String msg, boolean mustCatch)
throws Throwable {
countTest();
MethodHandle tf = MethodHandles.tryFinally(target, cleanup);
String result = null;
boolean isVoid = target.type().returnType() == void.class;
String[] argArray = new String[]{input};
try {
if (isVoid) {
tf.invoke(argArray);
} else {
result = (String) tf.invoke(input);
}
} catch (Throwable t) {
assertTrue(mustCatch);
assertEquals(msg, t.getMessage());
return;
}
assertFalse(mustCatch);
if (isVoid) {
assertEquals(msg, argArray[0]);
} else {
assertEquals(msg, result);
}
}
示例2: testTryFinallyNegative
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test(dataProvider = "negativeTestData")
public static void testTryFinallyNegative(MethodHandle target, MethodHandle cleanup, String expectedMessage) {
boolean caught = false;
try {
MethodHandles.tryFinally(target, cleanup);
} catch (IllegalArgumentException iae) {
assertEquals(expectedMessage, iae.getMessage());
caught = true;
}
assertTrue(caught);
}
示例3: testTryFinally
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test
public static void testTryFinally() throws Throwable {
MethodHandle hello = MethodHandles.tryFinally(TryFinally.MH_greet, TryFinally.MH_exclaim);
assertEquals(TryFinally.MT_hello, hello.type());
assertEquals("Hello, world!", hello.invoke("world"));
}
示例4: testTryFinallyVoid
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test
public static void testTryFinallyVoid() throws Throwable {
MethodHandle tfVoid = MethodHandles.tryFinally(TryFinally.MH_print, TryFinally.MH_printMore);
assertEquals(TryFinally.MT_printHello, tfVoid.type());
tfVoid.invoke("world");
}
示例5: testTryFinallySublist
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test
public static void testTryFinallySublist() throws Throwable {
MethodHandle helloMore = MethodHandles.tryFinally(TryFinally.MH_greetMore, TryFinally.MH_exclaimMore);
assertEquals(TryFinally.MT_moreHello, helloMore.type());
assertEquals("Hello, world and universe (but world first)!", helloMore.invoke("world", "universe"));
}
示例6: testTryFinallyOmitTrailingArguments
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Test(dataProvider = "omitTrailingArguments")
public static void testTryFinallyOmitTrailingArguments(MethodHandle cleanup) throws Throwable {
MethodHandle tf = MethodHandles.tryFinally(TryFinally.MH_dummyTarget, cleanup);
tf.invoke(1, 2L, "a", 23, 42L, "b");
}