Features track
Java 19: JEP 425: Virtual Threads (preview)
Java 19: JEP 428: Structured concurrency (incubator)
👍⭐Awesome feature track for all versions with examples
Pattern Matching for
switch
supporting type patterns and guarded patterns (Preview 🔍) JDK 18 JDK 17String formatted = switch (o) { case Integer i && i > 10 -> String.format("a large Integer %d", i); case Integer i -> String.format("a small Integer %d", i); case Long l -> String.format("a Long %d", l); default -> o.toString(); };
→ Related: Inside Java - Episode 17 “Pattern Matching for switch” with Gavin Bierman
Sealed Classes can restrict which other classes may extend them JDK 17 (Preview 🔍 in JDK 16 JDK 15)
public abstract sealed class Shape permits Circle, Rectangle {...} public final class Circle extends Shape {...} // OK public final class Rectangle extends Shape {...} // OK public final class Triangle extends Shape {...} // Compile error // No need for default case if all permitted types are covered double area = switch (shape) { case Circle c -> Math.pow(c.radius(), 2) * Math.PI case Rectangle r -> r.a() * r.b() };
Record Classes, terse syntax to define immutable DTOs JDK 16 (Preview 🔍 in JDK 15 JDK 14)
record Point(int x, int y) { } var point = new Point(1, 2); point.x(); // returns 1 point.y(); // returns 2
→ Related: Inside Java - Episode 14 “Records Serialization” with Julia Boes and Chris Hegarty
Opt-in and backwards-compatible Module System to avoid
ClassDefNotFoundErrors
at runtime and create internal APIs JDK 9 (Project Jigsaw)module hu.advancedweb.helloworld { requires hu.advancedweb.somedependency; exports hu.advancedweb.hello }
Private methods in interfaces JDK 9 (Milling Project Coin)
Diamond operator for anonymous inner classes JDK 9 (Milling Project Coin)
Try-with-resources allows effectively final variables JDK 9 (Milling Project Coin)
@SafeVargs
on private instance methods JDK 9 (Milling Project Coin)No deprecation warnings on
import
statements JDK 9
Last updated
Was this helpful?