Java8 to Java17
Java8 to Java17
A categorized list of all Java and JVM features since JDK 8 to 21
Record Classes, terse syntax to define immutable DTOs.
jdk16
1
2
3
4
5
record Point(int x, int y) { }
var point = new Point(1, 2);
point.x(); // returns 1
point.y(); // returns 2
Pattern Matching for instanceof to eliminate the need for explicit casts after a type check.
jdk16
1
2
3
if (obj instanceof String s && s.length() > 5) {
System.out.println(s);
}
Text Blocks
jdk15
1
2
3
4
5
6
String html = """
<html>
<body>
</body>
</html>
""";
Switch Expressions
jdk14
1
2
3
4
5
6
7
8
int numLetters = switch(day) {
case MONDAY -> 6;
default -> {
String s = day.toString();
int result = s.length();
yield result;
}
}
#####
This post is licensed under CC BY 4.0 by the author.