java.lang.invoke.MethodHandleProxies Java Examples

The following examples show how to use java.lang.invoke.MethodHandleProxies. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MethodHandlesProxiesTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
    public static void testOverriddenDefaultMethods() throws Throwable {
    MethodHandle target = MethodHandles.constant(String.class, "F");
    Override proxy = MethodHandleProxies.asInterfaceInstance(Override.class, target);

    assertEquals(proxy.a(), "OA");
    assertEquals(proxy.b(), "OB");
    assertEquals(proxy.c(), "OC");
}
 
Example #2
Source File: MethodHandlesProxiesTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
    public static void testOverriddenDefaultMethods() throws Throwable {
    MethodHandle target = MethodHandles.constant(String.class, "F");
    Override proxy = MethodHandleProxies.asInterfaceInstance(Override.class, target);

    assertEquals(proxy.a(), "OA");
    assertEquals(proxy.b(), "OB");
    assertEquals(proxy.c(), "OC");
}
 
Example #3
Source File: MethodHandlesProxiesTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
    public static void testDefaultMethods() throws Throwable {
    MethodHandle target = MethodHandles.constant(String.class, "F");
    C proxy = MethodHandleProxies.asInterfaceInstance(C.class, target);

    assertEquals(proxy.f(), "F");
    assertEquals(proxy.a(), "A");
    assertEquals(proxy.b(), "B");
    assertEquals(proxy.c(), "C");
    assertEquals(proxy.concat(), "ABC");
}
 
Example #4
Source File: ProxyForMethodHandle.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * MethodHandleProxies will add qualified export of sun.invoke from java.base
 * to a dynamic module
 */
@Test
public static void testRunnableMethodHandle() throws Exception {
    MethodHandles.Lookup lookup = MethodHandles.lookup();
    MethodType mt = MethodType.methodType(void.class);
    MethodHandle mh = lookup.findStatic(ProxyForMethodHandle.class, "runForRunnable", mt);
    Runnable proxy = MethodHandleProxies.asInterfaceInstance(Runnable.class, mh);
    proxy.run();

    Class<?> proxyClass = proxy.getClass();
    Module target = proxyClass.getModule();
    assertDynamicModule(target, proxyClass.getClassLoader(), proxyClass);
}
 
Example #5
Source File: MethodHandlesProxiesTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
    public static void testOverriddenDefaultMethods() throws Throwable {
    MethodHandle target = MethodHandles.constant(String.class, "F");
    Override proxy = MethodHandleProxies.asInterfaceInstance(Override.class, target);

    assertEquals(proxy.a(), "OA");
    assertEquals(proxy.b(), "OB");
    assertEquals(proxy.c(), "OC");
}
 
Example #6
Source File: MethodHandlesProxiesTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
    public static void testDefaultMethods() throws Throwable {
    MethodHandle target = MethodHandles.constant(String.class, "F");
    C proxy = MethodHandleProxies.asInterfaceInstance(C.class, target);

    assertEquals(proxy.f(), "F");
    assertEquals(proxy.a(), "A");
    assertEquals(proxy.b(), "B");
    assertEquals(proxy.c(), "C");
    assertEquals(proxy.concat(), "ABC");
}
 
Example #7
Source File: MethodHandlesProxiesTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
    public static void testOverriddenDefaultMethods() throws Throwable {
    MethodHandle target = MethodHandles.constant(String.class, "F");
    Override proxy = MethodHandleProxies.asInterfaceInstance(Override.class, target);

    assertEquals(proxy.a(), "OA");
    assertEquals(proxy.b(), "OB");
    assertEquals(proxy.c(), "OC");
}
 
Example #8
Source File: MethodHandlesProxiesTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
    public static void testDefaultMethods() throws Throwable {
    MethodHandle target = MethodHandles.constant(String.class, "F");
    C proxy = MethodHandleProxies.asInterfaceInstance(C.class, target);

    assertEquals(proxy.f(), "F");
    assertEquals(proxy.a(), "A");
    assertEquals(proxy.b(), "B");
    assertEquals(proxy.c(), "C");
    assertEquals(proxy.concat(), "ABC");
}
 
Example #9
Source File: MethodHandlesProxiesTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
    public static void testDefaultMethods() throws Throwable {
    MethodHandle target = MethodHandles.constant(String.class, "F");
    C proxy = MethodHandleProxies.asInterfaceInstance(C.class, target);

    assertEquals(proxy.f(), "F");
    assertEquals(proxy.a(), "A");
    assertEquals(proxy.b(), "B");
    assertEquals(proxy.c(), "C");
    assertEquals(proxy.concat(), "ABC");
}
 
Example #10
Source File: MHProxiesTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void testProxy() throws NoSuchMethodException, IllegalAccessException {
    MethodHandle m = MethodHandles.lookup().findStatic(MHProxiesTest.class, "m",
                                                       MethodType.methodType(Byte.class, int.class));
    Sam s = MethodHandleProxies.asInterfaceInstance(Sam.class, m);
    assertEquals(66d, s.m(66));
}
 
Example #11
Source File: MHProxiesTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void testProxy() throws NoSuchMethodException, IllegalAccessException {
    MethodHandle m = MethodHandles.lookup().findStatic(MHProxiesTest.class, "m",
                                                       MethodType.methodType(Byte.class, int.class));
    Sam s = MethodHandleProxies.asInterfaceInstance(Sam.class, m);
    assertEquals(66d, s.m(66));
}
 
Example #12
Source File: MHProxiesTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void testProxy() throws NoSuchMethodException, IllegalAccessException {
    MethodHandle m = MethodHandles.lookup().findStatic(MHProxiesTest.class, "m",
                                                       MethodType.methodType(Byte.class, int.class));
    Sam s = MethodHandleProxies.asInterfaceInstance(Sam.class, m);
    assertEquals(66d, s.m(66));
}
 
Example #13
Source File: MHProxiesTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void testProxy() throws NoSuchMethodException, IllegalAccessException {
    MethodHandle m = MethodHandles.lookup().findStatic(MHProxiesTest.class, "m",
                                                       MethodType.methodType(Byte.class, int.class));
    Sam s = MethodHandleProxies.asInterfaceInstance(Sam.class, m);
    assertEquals(66d, s.m(66));
}
 
Example #14
Source File: MHProxiesTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void testProxy() throws NoSuchMethodException, IllegalAccessException {
    MethodHandle m = MethodHandles.lookup().findStatic(MHProxiesTest.class, "m",
                                                       MethodType.methodType(Byte.class, int.class));
    Sam s = MethodHandleProxies.asInterfaceInstance(Sam.class, m);
    assertEquals(66d, s.m(66));
}
 
Example #15
Source File: MHProxiesTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void testProxy() throws NoSuchMethodException, IllegalAccessException {
    MethodHandle m = MethodHandles.lookup().findStatic(MHProxiesTest.class, "m",
                                                       MethodType.methodType(Byte.class, int.class));
    Sam s = MethodHandleProxies.asInterfaceInstance(Sam.class, m);
    assertEquals(66d, s.m(66));
}
 
Example #16
Source File: MHProxiesTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void testProxy() throws NoSuchMethodException, IllegalAccessException {
    MethodHandle m = MethodHandles.lookup().findStatic(MHProxiesTest.class, "m",
                                                       MethodType.methodType(Byte.class, int.class));
    Sam s = MethodHandleProxies.asInterfaceInstance(Sam.class, m);
    assertEquals(66d, s.m(66));
}
 
Example #17
Source File: MHProxiesTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void testProxy() throws NoSuchMethodException, IllegalAccessException {
    MethodHandle m = MethodHandles.lookup().findStatic(MHProxiesTest.class, "m",
                                                       MethodType.methodType(Byte.class, int.class));
    Sam s = MethodHandleProxies.asInterfaceInstance(Sam.class, m);
    assertEquals(66d, s.m(66));
}
 
Example #18
Source File: MHProxiesTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void testProxy() throws NoSuchMethodException, IllegalAccessException {
    MethodHandle m = MethodHandles.lookup().findStatic(MHProxiesTest.class, "m",
                                                       MethodType.methodType(Byte.class, int.class));
    Sam s = MethodHandleProxies.asInterfaceInstance(Sam.class, m);
    assertEquals(66d, s.m(66));
}
 
Example #19
Source File: MHProxiesTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void testProxy() throws NoSuchMethodException, IllegalAccessException {
    MethodHandle m = MethodHandles.lookup().findStatic(MHProxiesTest.class, "m",
                                                       MethodType.methodType(Byte.class, int.class));
    Sam s = MethodHandleProxies.asInterfaceInstance(Sam.class, m);
    assertEquals(66d, s.m(66));
}
 
Example #20
Source File: MHProxiesTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void testProxy() throws NoSuchMethodException, IllegalAccessException {
    MethodHandle m = MethodHandles.lookup().findStatic(MHProxiesTest.class, "m",
                                                       MethodType.methodType(Byte.class, int.class));
    Sam s = MethodHandleProxies.asInterfaceInstance(Sam.class, m);
    assertEquals(66d, s.m(66));
}
 
Example #21
Source File: MHProxiesTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void testProxy() throws NoSuchMethodException, IllegalAccessException {
    MethodHandle m = MethodHandles.lookup().findStatic(MHProxiesTest.class, "m",
                                                       MethodType.methodType(Byte.class, int.class));
    Sam s = MethodHandleProxies.asInterfaceInstance(Sam.class, m);
    assertEquals(66d, s.m(66));
}
 
Example #22
Source File: MHProxiesTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void testProxy() throws NoSuchMethodException, IllegalAccessException {
    MethodHandle m = MethodHandles.lookup().findStatic(MHProxiesTest.class, "m",
                                                       MethodType.methodType(Byte.class, int.class));
    Sam s = MethodHandleProxies.asInterfaceInstance(Sam.class, m);
    assertEquals(66d, s.m(66));
}