Skip to content

Commit 1ffd6b2

Browse files
committed
Update Java 18 test class ...
- samples only for standard features - markdown javadoc for JEPs
1 parent 3e7d40e commit 1ffd6b2

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/test/java/pl/mperor/lab/java/Java18.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,21 @@
1414
import java.net.UnknownHostException;
1515
import java.nio.charset.Charset;
1616

17-
/**
18-
* Java 18 (March 2022)
19-
*/
17+
/// Java 18™ (March 2022)
18+
/// [JDK 18](https://openjdk.org/projects/jdk/18)
19+
///
20+
/// - STANDARD FEATURES:
21+
/// - 400: UTF-8 by Default
22+
/// - 408: Simple Web Server
23+
/// - 421: Deprecate Finalization for Removal
24+
/// - 418: Internet-Address Resolution SPI (service-provider interface)
25+
/// - 413: Code Snippets in Java API Documentation
26+
/// - 416: Reimplement Core Reflection with Method Handles
27+
///
28+
/// - PREVIEW & INCUBATOR:
29+
/// - 419: Foreign Function & Memory API (Second Incubator)
30+
/// - 420: Pattern Matching for switch (Second Preview)
31+
/// - 417: Vector API (Third Incubator)
2032
public class Java18 {
2133

2234
@Test
@@ -86,8 +98,11 @@ protected void finalize() throws Throwable {
8698

8799
@Test
88100
public void testInetAddressResolution() throws UnknownHostException {
89-
InetAddress address = InetAddress.getByName("localhost");
90-
Assertions.assertTrue(address.isLoopbackAddress());
101+
InetAddress localhost = InetAddress.getByName("localhost");
102+
Assertions.assertTrue(localhost.isLoopbackAddress());
103+
104+
InetAddress google = InetAddress.getByName("google.com");
105+
Assertions.assertNotNull(google.getAddress());
91106
}
92107

93108
@Test

src/test/java/pl/mperor/lab/java/Java7.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import java.io.Closeable;
88
import java.io.File;
99
import java.io.IOException;
10+
import java.lang.invoke.MethodHandle;
11+
import java.lang.invoke.MethodHandles;
12+
import java.lang.invoke.MethodType;
13+
import java.lang.reflect.Method;
1014
import java.nio.file.Files;
1115
import java.nio.file.Path;
1216
import java.util.concurrent.ForkJoinPool;
@@ -141,4 +145,14 @@ protected Integer compute() {
141145
}
142146
}
143147

148+
@Test
149+
public void testMethodHandlesVsCoreReflection() throws Throwable {
150+
Method method = String.class.getMethod("isEmpty");
151+
Assertions.assertTrue((boolean) method.invoke(""));
152+
153+
MethodHandles.Lookup lookup = MethodHandles.lookup();
154+
MethodHandle methodHandle = lookup.findVirtual(String.class, "isEmpty", MethodType.methodType(boolean.class));
155+
Assertions.assertTrue((boolean) methodHandle.invoke(""));
156+
}
157+
144158
}

0 commit comments

Comments
 (0)