Package java.lang.invoke

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


        MethodHandle handle = Binder
                .from(void.class, String[].class)
                .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]);
    }
View Full Code Here


        MethodHandle handle = Binder
                .from(void.class, String[].class)
                .tryFinally(post)
                .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) {
View Full Code Here

                .from(void.class, String[].class)
                .tryFinally(post)
                .catchException(BlahException.class, ignoreException)
                .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);
View Full Code Here

        MethodHandle handle = Binder
                .from(int.class, String[].class)
                .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]);
    }
View Full Code Here

        MethodHandle handle = Binder
                .from(int.class, String[].class)
                .tryFinally(post)
                .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) {
View Full Code Here

                .from(int.class, String[].class)
                .tryFinally(post)
                .catchException(BlahException.class, ignoreException)
                .invokeStatic(LOOKUP, BinderTest.class, "setZeroToFooReturnIntAndRaise");

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

    public void testArraySet() throws Throwable {
        MethodHandle handle = Binder
                .from(void.class, Object[].class, int.class, Object.class)
                .arraySet();

        assertEquals(MethodType.methodType(void.class, Object[].class, int.class, Object.class), handle.type());
        Object[] ary = new Object[1];
        handle.invokeExact(ary, 0, (Object)"foo");
        assertEquals(ary[0], "foo");
    }
View Full Code Here

    public void testArrayGet() throws Throwable {
        MethodHandle handle = Binder
                .from(Object.class, Object[].class, int.class)
                .arrayGet();

        assertEquals(MethodType.methodType(Object.class, Object[].class, int.class), handle.type());
        Object[] ary = new Object[] {"foo"};
        assertEquals(handle.invokeExact(ary, 0), "foo");
    }
   
    @Test
View Full Code Here

                        Binder
                                .from(String.class, String.class)
                                .invokeStatic(LOOKUP, BinderTest.class, "addBaz")
                );
       
        assertEquals(MethodType.methodType(String.class, String.class), handle.type());
        assertEquals("foobar", (String)handle.invokeExact("foo"));
        assertEquals("quuxbaz", (String)handle.invokeExact("quux"));
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
View Full Code Here

        MethodHandle handle = stringObjectInt
                .appendArg("flo", float.class)
                .appendArg("dub", double.class)
                .permuteWith(stringObjectIntTarget, "obj", "num");
       
        assertEquals(MethodType.methodType(String.class, Object.class, int.class, float.class, double.class), handle.type());
        assertEquals("foo1", (String)handle.invokeExact((Object)"foo", 1, 1.0f, 1.0));
    }
   
    @Test
    public void testPermuteWithSmartHandle() throws Throwable {
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.