Switch Expression ◦ After 2 previews, it’s now finalized ◦ All cases enforced by the compiler boolean workDay = switch(dayOfWeek) { case SATURDAY, SUNDAY -> false; default -> true; }
Switch Expression ◦ After 2 previews, it’s now finalized ◦ All cases enforced by the compiler boolean workDay = switch(dayOfWeek) { case SATURDAY, SUNDAY -> false; default -> true; }
to return a value ◦ Not a keyword, can still be used as a variable name boolean workDay = switch (day) { case SATURDAY, SUNDAY -> { System.err.println("Weekend"); yield false; } default -> true; }
NullPointerException • -XX:+ShowCodeDetailsInExceptionMessages var a = c.b.a; Exception in thread "main" java.lang.NullPointerException: Cannot read field "a" because "c.b" is null
- Foreign Memory Access API (incubating) • MemorySegment ◦ A contiguous region of memory (spatially bounded) ◦ Explicitly deallocated (temporally bounded) • MemoryLayout ◦ A (named) description of a memory segment • Finally, struct and union in Java!
} var cxs = new Complex[128]; Java 14 - Foreign Memory Access WARNING! C code! struct { double x; double y; } complex[128]; x y x y x y 0 1 2 3 4 5 x hdr x y hdr y x hdr y 0 1 2
in a game. SequenceLayout shape = MemoryLayout.ofSequence(128, complex); var ys = shape.varHandle(long.class, PathElement.sequenceElement(), PathElement.groupElement("y")); ys.set(shape.baseAddress(), 1L, 13L); x y x y x y x y x 13 x y
to close the segment. try (MemorySegment segment = MemorySegment.allocateNative(shape)) { // Translate the shape on the y axis. for (long i = 0; i < shape.elementCount().orElse(0); ++i) { // Get the current y coordinate. long y = (Long)ys.get(segment.baseAddress(), i); // Set the new y coordinate. ys.set(segment.baseAddress(), i, y + 1); } }
• Records are immutable, final, data holder classes ◦ Typed tuples • Automatic constructor and getters ◦ Plus equals(), hashCode(), toString() public record MinMax(int min, int max) {}
= minMax.min; // field access ◦ int m = minMax.max(); // getter access ◦ IntSupplier s = minMax::max; // getter access • Records can be customized ◦ Custom constructors ◦ Override equals(), hashCode() and toString() ◦ Add methods (both static and virtual) ◦ Fields cannot be named hashCode, toString, wait...
• 1-1 relationship between data and class ◦ Easy to deconstruct a record, recursively record Pctl(int p50, int p90, int p95, int p99) {} record Stats(Pctl percentile, MinMax minMax) {}
• Value Types => flat and dense object layout in memory ◦ But must give up identity and nullability • Records => data tuple and deconstruction ◦ But must give up extension, hiding and mutability • May need both at the same time
349: JFR Event Streaming ◦ JEP 352: Non-Volatile Mapped Byte Buffers ◦ JEP 345: NUMA aware allocation for G1 ◦ JEP 364-5: ZGC on macOS + Windows • Deprecations ◦ JEP 362: Deprecate the Solaris and SPARC Ports (gone in Java 15) • Removals ◦ JEP 363: Remove CMS ◦ JEP 367: Remove the Pack200 Tools and API