-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava10.java
More file actions
69 lines (60 loc) · 2.36 KB
/
Copy pathJava10.java
File metadata and controls
69 lines (60 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package pl.mperor.lab.java;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/// Java 10™ (March 2018)
/// [JDK 10](https://openjdk.org/projects/jdk/10)
///
/// - STANDARD FEATURES:
/// - 286: Local-Variable Type Inference
/// - 296: Consolidate the JDK Forest into a Single Repository
/// - 304: Garbage-Collector Interface
/// - 307: Parallel Full GC for G1
/// - 310: Application Class-Data Sharing
/// - 312: Thread-Local Handshakes
/// - 314: Additional Unicode Language-Tag Extensions
/// - 316: Heap Allocation on Alternative Memory Devices
/// - 317: Experimental Java-Based JIT Compiler
/// - 319: Root Certificates
/// - 322: Time-Based Release Versioning
/// - 313: Remove the Native-Header Generation Tool (javah)
public class Java10 {
@Test
public void testLocalVariableTypeInferenceKeywordAkaVar() {
var message = "Hello Java 10!";
// same as String message = ...
Assertions.assertEquals("Hello Java 10!", message);
var number = 10;
// same as int number = ...
Assertions.assertEquals(10, number);
}
@Test
public void testUnmodifiableCollectionCopyOf() {
var original = List.of("Java", "Python", "JavaScript");
var copy = List.copyOf(original);
Assertions.assertEquals(original, copy);
Assertions.assertThrows(UnsupportedOperationException.class, () -> copy.add("Ruby"));
}
@Test
public void testOptionalEnhancements() {
Optional<String> optional = Optional.empty();
Assertions.assertThrows(IllegalStateException.class, () -> optional.orElseThrow(IllegalStateException::new));
Assertions.assertEquals("", optional.stream().collect(Collectors.joining()));
}
@Test
public void testCompletableFutureTimeout() {
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return "Result";
}).orTimeout(10, TimeUnit.MILLISECONDS);
Assertions.assertThrows(Exception.class, future::join);
}
}