Package java.lang.invoke

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


                .from(String.class, String.class, Object.class)
                .drop(1)
                .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 testDropLast() throws Throwable {
View Full Code Here


                .from(String.class, String.class, Object.class)
                .dropLast()
                .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()));

        handle = Binder
                .from(String.class, String.class, Object.class, double.class)
                .dropLast(2)
View Full Code Here

                .from(String.class, String.class, Object.class, double.class)
                .dropLast(2)
                .insert(1, "world")
                .invoke(target);

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

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

                .from(String.class, Object.class, String.class)
                .dropFirst()
                .insert(1, "world")
                .invoke(target);

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

        handle = Binder
                .from(String.class, Object.class, double.class, String.class)
                .dropFirst(2)
View Full Code Here

                .from(String.class, Object.class, double.class, String.class)
                .dropFirst(2)
                .insert(1, "world")
                .invoke(target);

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

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

                .from(String.class, String.class, Object.class)
                .dropAll()
                .insert(0, "Hello, ", "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 testConvert() throws Throwable {
View Full Code Here

        MethodHandle handle = Binder
                .from(String.class, Object.class, Integer.class, Float.class)
                .convert(target.type())
                .invoke(target);

        assertEquals(MethodType.methodType(String.class, Object.class, Integer.class, Float.class), handle.type());
        assertEquals(null, (String) handle.invokeExact((Object) "foo", (Integer) 5, (Float) 5.0f));
    }

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

        MethodHandle handle = Binder
                .from(String.class, Object.class, Integer.class, Float.class)
                .convert(target.type().returnType(), target.type().parameterArray())
                .invoke(target);

        assertEquals(MethodType.methodType(String.class, Object.class, Integer.class, Float.class), handle.type());
        assertEquals(null, (String)handle.invokeExact((Object)"foo", (Integer)5, (Float)5.0f));
    }

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

        MethodHandle handle = Binder
                .from(String.class, Object.class, byte.class, int.class)
                .cast(target.type())
                .invoke(target);

        assertEquals(MethodType.methodType(String.class, Object.class, byte.class, int.class), handle.type());
        assertEquals(null, (String)handle.invokeExact((Object)"foo", (byte)5, 5));
    }

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

        MethodHandle handle = Binder
                .from(String.class, Object.class, byte.class, int.class)
                .cast(target.type().returnType(), target.type().parameterArray())
                .invoke(target);

        assertEquals(MethodType.methodType(String.class, Object.class, byte.class, int.class), handle.type());
        assertEquals(null, (String)handle.invokeExact((Object)"foo", (byte)5, 5));
    }

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