Package java.lang.invoke

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


                .from(String.class, Integer.class, Float.class, String.class)
                .drop(0, 2)
                .permute(0, 0)
                .invoke(target);

        assertEquals(MethodType.methodType(String.class, Integer.class, Float.class, String.class), handle.type());
        assertEquals("foofoo", (String)handle.invokeExact((Integer) 0, (Float) 0.0f, "foo"));
    }

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


        MethodHandle handle = Binder
                .from(String.class, Object[].class)
                .spread(String.class, String.class)
                .invoke(target);
       
        assertEquals(MethodType.methodType(String.class, Object[].class), handle.type());
        assertEquals("foobar", (String)handle.invokeExact(new Object[] {"foo", "bar"}));
    }

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

        MethodHandle handle = Binder
                .from(String.class, String[].class)
                .spread(2)
                .invoke(target);
       
        assertEquals(MethodType.methodType(String.class, String[].class), handle.type());
        assertEquals("foobar", (String)handle.invokeExact(new String[] {"foo", "bar"}));
    }

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

        MethodHandle handle = Binder
                .from(String[].class, String.class, String.class, String.class)
                .collect(1, String[].class)
                .invokeStatic(LOOKUP, BinderTest.class, "varargs");

        assertEquals(MethodType.methodType(String[].class, String.class, String.class, String.class), handle.type());
        String[] ary = (String[])handle.invokeExact("one", "two", "three");
        assertEquals(2, ary.length);
        assertEquals("two", ary[0]);
        assertEquals("three", ary[1]);
View Full Code Here

        MethodHandle handle2 = Binder
                .from(Subjects.StringIntegerIntegerIntegerString.type())
                .collect(1, 3, Integer[].class)
                .invoke(Subjects.StringIntegersStringHandle);

        assertEquals(MethodType.methodType(String.class, String.class, Integer.class, Integer.class, Integer.class, String.class), handle2.type());
        assertEquals("[foo, [1, 2, 3], bar]", (String)handle2.invokeExact("foo", new Integer(1), new Integer(2), new Integer(3), "bar"));
    }

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

        MethodHandle handle = Binder
                .from(String[].class, String.class, String.class, String.class)
                .varargs(1, String[].class)
                .invokeStatic(LOOKUP, BinderTest.class, "varargs");

        assertEquals(MethodType.methodType(String[].class, String.class, String.class, String.class), handle.type());
        String[] ary = (String[])handle.invokeExact("one", "two", "three");
        assertEquals(2, ary.length);
        assertEquals("two", ary[0]);
        assertEquals("three", ary[1]);
    }
View Full Code Here

    public void testConstant() throws Throwable {
        MethodHandle handle = Binder
                .from(String.class)
                .constant("hello");

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

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

    public void testConstant2() throws Throwable {
        MethodHandle handle = Binder
                .from(Object.class)
                .constant("hello");

        assertEquals(MethodType.methodType(Object.class), handle.type());
        assertEquals("hello", (Object)handle.invokeExact());
    }

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

    public void testIdentity() throws Throwable {
        MethodHandle handle = Binder
                .from(String.class, String.class)
                .identity();

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

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

        MethodHandle handle = Binder
                .from(String.class, String.class)
                .fold(fold)
                .invoke(target);

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

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