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