Package java.lang.invoke

Examples of java.lang.invoke.MethodHandle.invokeExact()


        MethodHandle handle = Binder
                .from(void.class, Fields.class, String.class)
                .setFieldQuiet(LOOKUP, "instanceField");

        assertEquals(MethodType.methodType(void.class, Fields.class, String.class), handle.type());
        handle.invokeExact(fields, "modified");
        assertEquals("modified", fields.instanceField);
    }

    @Test
    public void testSetStatic() throws Throwable {
View Full Code Here


            MethodHandle handle = Binder
                    .from(void.class, String.class)
                    .setStatic(LOOKUP, Fields.class, "staticField");

            assertEquals(MethodType.methodType(void.class, String.class), handle.type());
            handle.invokeExact("modified");
            assertEquals("modified", Fields.staticField);
        } finally {
            Fields.staticField = "initial";
        }
    }
View Full Code Here

            MethodHandle handle = Binder
                    .from(void.class, String.class)
                    .setStaticQuiet(LOOKUP, Fields.class, "staticField");

            assertEquals(MethodType.methodType(void.class, String.class), handle.type());
            handle.invokeExact("modified");
            assertEquals("modified", Fields.staticField);
        } finally {
            Fields.staticField = "initial";
        }
    }
View Full Code Here

                .from(void.class, int.class, String.class)
                .nop();
       
        assertEquals(MethodType.methodType(void.class, int.class, String.class), handle.type());
        try {
            handle.invokeExact(1, "foo");
        } catch (Throwable t) {
            assertTrue("should not reach here", false);
        }
    }
   
View Full Code Here

                .from(void.class, BlahException.class)
                .throwException();
       
        assertEquals(MethodType.methodType(void.class, BlahException.class), handle.type());
        try {
            handle.invokeExact(new BlahException());
            assertTrue("should not reach here", false);
        } catch (BlahException be) {
        }
    }
View Full Code Here

                .tryFinally(post)
                .invokeStatic(LOOKUP, BinderTest.class, "setZeroToFoo");

        assertEquals(MethodType.methodType(void.class, String[].class), handle.type());
        String[] stringAry = new String[1];
        handle.invokeExact(stringAry);
        assertEquals("foofinally", stringAry[0]);
    }

    @Test
    public void testTryFinally2() throws Throwable {
View Full Code Here

                .invokeStatic(LOOKUP, BinderTest.class, "setZeroToFooAndRaise");

        assertEquals(MethodType.methodType(void.class, String[].class), handle.type());
        String[] stringAry = new String[1];
        try {
            handle.invokeExact(stringAry);
            assertTrue("should not have reached here", false);
        } catch (BlahException re) {
        }
        assertEquals("foofinally", stringAry[0]);
    }
View Full Code Here

                .invokeStatic(LOOKUP, BinderTest.class, "setZeroToFooAndRaise");

        assertEquals(MethodType.methodType(void.class, String[].class), handle.type());
        String[] stringAry = new String[1];
        try {
            handle.invokeExact(stringAry);
        } catch (BlahException re) {
            assertTrue("should not have reached here", false);
        }
        assertEquals("foofinally", stringAry[0]);
    }
View Full Code Here

                .tryFinally(post)
                .invokeStatic(LOOKUP, BinderTest.class, "setZeroToFooReturnInt");

        assertEquals(MethodType.methodType(int.class, String[].class), handle.type());
        String[] stringAry = new String[1];
        assertEquals(1, (int)handle.invokeExact(stringAry));
        assertEquals("foofinally", stringAry[0]);
    }

    @Test
    public void testTryFinallyReturn2() throws Throwable {
View Full Code Here

                .invokeStatic(LOOKUP, BinderTest.class, "setZeroToFooReturnIntAndRaise");

        assertEquals(MethodType.methodType(int.class, String[].class), handle.type());
        String[] stringAry = new String[1];
        try {
            int x = (int)handle.invokeExact(stringAry);
            assertTrue("should not have reached here", false);
        } catch (BlahException re) {
        }
        assertEquals("foofinally", stringAry[0]);
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.