Package java.lang.invoke

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


    Method raw_handle = moduleClass.getMethod("raw_handle");
    result = raw_handle.invoke(null);
    assertThat(result, instanceOf(MethodHandle.class));
    handle = (MethodHandle) result;
    assertThat(handle.type(), is(genericMethodType(1)));
    assertThat((String) handle.invoke(123), is("123"));

    Method handle_with_capture = moduleClass.getMethod("handle_with_capture", Object.class, Object.class);
    result = handle_with_capture.invoke(null, 1, 2);
    assertThat(result, instanceOf(MethodHandle.class));
    handle = (MethodHandle) result;
View Full Code Here


    Method handle_with_capture = moduleClass.getMethod("handle_with_capture", Object.class, Object.class);
    result = handle_with_capture.invoke(null, 1, 2);
    assertThat(result, instanceOf(MethodHandle.class));
    handle = (MethodHandle) result;
    assertThat(handle.type(), is(genericMethodType(1)));
    assertThat((Integer) handle.invoke(100), is(300));
    assertThat((Integer) handle.invoke(10), is(30));

    Method call_with_invoke = moduleClass.getMethod("call_with_invoke");
    assertThat((Integer) call_with_invoke.invoke(null), is(90));
View Full Code Here

    result = handle_with_capture.invoke(null, 1, 2);
    assertThat(result, instanceOf(MethodHandle.class));
    handle = (MethodHandle) result;
    assertThat(handle.type(), is(genericMethodType(1)));
    assertThat((Integer) handle.invoke(100), is(300));
    assertThat((Integer) handle.invoke(10), is(30));

    Method call_with_invoke = moduleClass.getMethod("call_with_invoke");
    assertThat((Integer) call_with_invoke.invoke(null), is(90));

    Method call_with_ref = moduleClass.getMethod("call_with_ref");
View Full Code Here

    Method add_to = moduleClass.getMethod("add_to", Object.class);
    result = add_to.invoke(null, 1);
    assertThat(result, instanceOf(MethodHandle.class));
    handle = (MethodHandle) result;
    assertThat((Integer) handle.invoke(2), is(3));

    Method as_explicit_interface = moduleClass.getMethod("as_explicit_interface");
    assertThat((String) as_explicit_interface.invoke(null), is("Plop -> da plop"));

    Method executor_and_callable = moduleClass.getMethod("executor_and_callable");
View Full Code Here

    Method nested_compact = moduleClass.getMethod("nested_compact", Object.class);
    result = nested_compact.invoke(null, 1);
    assertThat(result, instanceOf(MethodHandle.class));
    handle = (MethodHandle) result;
    assertThat(handle.type(), is(genericMethodType(1)));
    assertThat((Integer) handle.invoke(2), is(3));

    Method in_a_map = moduleClass.getMethod("in_a_map");
    result = in_a_map.invoke(null);
    assertThat(result, notNullValue());
    assertThat((Integer) result, is(4));
View Full Code Here

    Method nested_closures = moduleClass.getMethod("nested_closures");
    result = nested_closures.invoke(null);
    assertThat(result, notNullValue());
    assertThat(result, instanceOf(MethodHandle.class));
    handle = (MethodHandle) result;
    assertThat((String) handle.invoke(), is("plop"));

    Method closure_with_varargs_and_capture = moduleClass.getMethod("closure_with_varargs_and_capture");
    assertThat((String) closure_with_varargs_and_capture.invoke(null), is("> 6"));

    Method closure_with_varargs_array_and_capture = moduleClass.getMethod("closure_with_varargs_array_and_capture");
View Full Code Here

    assertThat(result, instanceOf(MethodHandle.class));

    MethodHandle handle = (MethodHandle) result;
    assertThat(handle.type(), is(methodType(Object.class, Object.class, Object.class)));

    result = handle.invoke("foo", "bar");
    assertThat(result, instanceOf(List.class));
    assertThat(((List) result).size(), is(2));
  }

  @Test
View Full Code Here

    assertThat(result, instanceOf(MethodHandle.class));

    MethodHandle handle = (MethodHandle) result;
    assertThat(handle.type(), is(methodType(Object.class, Object[].class)));

    result = handle.invoke("foo", "bar");
    assertThat(result, instanceOf(String.class));
    assertThat((String) result, is("foobar"));
  }
}
View Full Code Here

  @Test
  public void nullsafe_invocation() throws Throwable {
    CallSite toString = MethodInvocationSupport.bootstrap(lookup(), "toString", methodType(Object.class, Object.class), 1);

    MethodHandle invoker = toString.dynamicInvoker();
    assertThat(invoker.invoke(null), nullValue());
    assertThat((String) invoker.invoke("a"), is("a"));
    assertThat((String) invoker.invoke("b"), is("b"));
    assertThat(invoker.invoke(null), nullValue());
  }
View Full Code Here

  public void nullsafe_invocation() throws Throwable {
    CallSite toString = MethodInvocationSupport.bootstrap(lookup(), "toString", methodType(Object.class, Object.class), 1);

    MethodHandle invoker = toString.dynamicInvoker();
    assertThat(invoker.invoke(null), nullValue());
    assertThat((String) invoker.invoke("a"), is("a"));
    assertThat((String) invoker.invoke("b"), is("b"));
    assertThat(invoker.invoke(null), nullValue());
  }

  @Test
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.