Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/invoke/MethodHandlesProxiesTest.java
47216 views
1
/*
2
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
* @bug 8206955
26
* @run testng/othervm -ea -esa test.java.lang.invoke.MethodHandlesProxiesTest
27
*/
28
29
package test.java.lang.invoke;
30
31
import org.testng.annotations.Test;
32
33
import java.lang.invoke.MethodHandle;
34
import java.lang.invoke.MethodHandleProxies;
35
import java.lang.invoke.MethodHandles;
36
37
import static org.testng.Assert.assertEquals;
38
39
public class MethodHandlesProxiesTest {
40
41
public interface A {
42
default String a() {
43
return "A";
44
}
45
}
46
47
public interface B {
48
default String b() {
49
return "B";
50
}
51
}
52
53
public interface C extends A, B {
54
String f();
55
56
default String c() {
57
return "C";
58
}
59
60
default String concat() {
61
return a() + b() + c();
62
}
63
}
64
65
public interface Override extends C {
66
String f();
67
68
default String a() {
69
return "OA";
70
}
71
72
default String b() {
73
return "OB";
74
}
75
76
default String c() {
77
return "OC";
78
}
79
}
80
81
@Test
82
public static void testDefaultMethods() throws Throwable {
83
MethodHandle target = MethodHandles.constant(String.class, "F");
84
C proxy = MethodHandleProxies.asInterfaceInstance(C.class, target);
85
86
assertEquals(proxy.f(), "F");
87
assertEquals(proxy.a(), "A");
88
assertEquals(proxy.b(), "B");
89
assertEquals(proxy.c(), "C");
90
assertEquals(proxy.concat(), "ABC");
91
}
92
93
@Test
94
public static void testOverriddenDefaultMethods() throws Throwable {
95
MethodHandle target = MethodHandles.constant(String.class, "F");
96
Override proxy = MethodHandleProxies.asInterfaceInstance(Override.class, target);
97
98
assertEquals(proxy.a(), "OA");
99
assertEquals(proxy.b(), "OB");
100
assertEquals(proxy.c(), "OC");
101
}
102
}
103
104