Package java.lang.invoke

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


        MethodHandle handle = SmartBinder
                .from(String.class, new String[]{"arg1", "arg2"}, String.class, String.class)
                .filter("arg.*", filter)
                .invoke(target).handle();

        assertEquals(MethodType.methodType(String.class, String.class, String.class), handle.type());
        assertEquals("foogoodbyebargoodbye", (String)handle.invokeExact("foo", "bar"));
    }

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


                .fold("s", stringInt)
                .dropLast()
                .identity()
                .handle();

        assertEquals(MethodType.methodType(String.class, int.class), handle.type());
        assertEquals("15", (String)handle.invokeExact(15));
    }
   
    private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
   
View Full Code Here

        MethodHandle handle = Binder
                .from(binder1)
                .insert(1, "world")
                .invoke(target);

        assertEquals(MethodType.methodType(String.class, String.class, Object.class), handle.type());
        assertEquals("Hello, world", (String) handle.invokeExact("Hello, ", new Object()));
    }

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

        MethodHandle handle = Binder
                .from(String.class)
                .insert(0, new Class[]{int.class, long.class}, 1, 1L)
                .invoke(target);

        assertEquals(MethodType.methodType(String.class), handle.type());
        assertEquals("intLong ok", (String) handle.invokeExact());
    }

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

        MethodHandle handle = Binder
                .from(String.class, String.class)
                .insert(1, "world")
                .invoke(target);

        assertEquals(MethodType.methodType(String.class, String.class), handle.type());
        assertEquals("Hello, world", (String) handle.invokeExact("Hello, "));

        MethodHandle target2 = Subjects.concatCharSequenceHandle();
        MethodHandle handle2 = Binder
                .from(String.class, String.class)
View Full Code Here

        MethodHandle handle2 = Binder
                .from(String.class, String.class)
                .insert(1, CharSequence.class, "world")
                .invoke(target2);

        assertEquals(MethodType.methodType(String.class, String.class), handle2.type());
        assertEquals("Hello, world", (String) handle2.invokeExact("Hello, "));
    }

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

                .from(String.class, String.class, Object.class)
                .append("world")
                .drop(1)
                .invoke(target);

        assertEquals(MethodType.methodType(String.class, String.class, Object.class), handle.type());
        assertEquals("Hello, world", (String) handle.invokeExact("Hello, ", new Object()));

        MethodHandle target2 = Subjects.concatCharSequenceHandle();
        MethodHandle handle2 = Binder
                .from(String.class, String.class, Object.class)
View Full Code Here

                .from(String.class, String.class, Object.class)
                .append(CharSequence.class, "world")
                .drop(1)
                .invoke(target2);

        assertEquals(MethodType.methodType(String.class, String.class, Object.class), handle2.type());
        assertEquals("Hello, world", (String) handle2.invokeExact("Hello, ", new Object()));
    }

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

                .from(String.class, Object.class, String.class)
                .prepend("Hello, ")
                .drop(1)
                .invoke(target);

        assertEquals(MethodType.methodType(String.class, Object.class, String.class), handle.type());
        assertEquals("Hello, world", (String) handle.invokeExact(new Object(), "world"));

        MethodHandle target2 = Subjects.concatHandle();
        MethodHandle handle2 = Binder
                .from(String.class, Object.class, String.class)
View Full Code Here

                .from(String.class, Object.class, String.class)
                .prepend(String.class, "Hello, ")
                .drop(1)
                .invoke(target2);

        assertEquals(MethodType.methodType(String.class, Object.class, String.class), handle2.type());
        assertEquals("Hello, world", (String) handle2.invokeExact(new Object(), "world"));
    }

    @Test
    public void testDropInsert() 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.