You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: java-21/README.md
+39-1Lines changed: 39 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,17 +20,28 @@ To run each example use: `java --enable-preview --source 21 <FileName.java>`
20
20
## Features
21
21
22
22
* Virtual threads
23
+
* promotion to standard
23
24
* changed to make virtual threads always support thread-local
24
25
* in preview releases was possible to create a virtual thread without thread-local support
25
26
* flag `jdk.traceVirtualThreadLocals` to show the strack trace when a virtual threads sets a value in thread-local variable
26
27
* Record patterns
28
+
* promotion to standard
27
29
* the main change is remove the support for record pattern in header of an enhanced for loop
28
30
* Pattern matching for `switch`
31
+
* promotion to standard
29
32
* main changes from last JEPs:
30
33
* removed parenthesized patterns (`case int i when (i > 0)`)
31
-
* allow qualified enum constants as case constants
34
+
* allow qualified enum constants as case constants (`case MyEnum.ITEM`)
32
35
* exhaustiveness and compatibility:
33
36
* compiler will only require exhaustiveness if the switch uses any pattern, null label or if selector expression isn't from a legacy type (char, byte, short, int, Character, Byte, Short, Integer, String or a enum)
37
+
* improved switch to support pattern matching for types (like `instanceof`)
38
+
* support for `null` case
39
+
* support for guards where we can use a boolean expression (`case String s when s.length > 10`)
40
+
* scope for pattern variable:
41
+
* the scope of pattern variable in visible only in the guard clause and the case body (expression, block or throw)
42
+
* fall through:
43
+
*`switch` with type pattern doesn't support falling through
44
+
* if using case label with `:`, we must end the block with `break` or `yield` (`case String s: ...; break;`, `case String s: ...; yield s.length();`)
34
45
* String templates:
35
46
* improve the string with embedded expressions and template processors
36
47
* goals:
@@ -106,6 +117,7 @@ To run each example use: `java --enable-preview --source 21 <FileName.java>`
106
117
* `unmodifiableSequencedSet`
107
118
* `unmodifiableSequencedMap`
108
119
* Unnamed classes and instance main methods
120
+
* a.k.a. relaxed launch protocol
109
121
* facilitate the writing of first programm for students without needing to know another features designed for large programs
110
122
* unnamed class:
111
123
* any method declared in a source file without an enclosed class will be considered to be member of an unnamed top-level class
@@ -149,6 +161,32 @@ To run each example use: `java --enable-preview --source 21 <FileName.java>`
149
161
* `static void main()`
150
162
* `void main(String[])`
151
163
* `void main()`
164
+
* Unnamed patterns and variables
165
+
* goals:
166
+
* improve the readability of record patterns by ediling unnecessary nested patterns
167
+
* improve the maintanability of code by identifying variables that must be declared but will not be used
168
+
* unnamed pattern is denoted by `_`
169
+
* it is a shorthand for the type pattern `var _`
170
+
* it will facilitate the pattern matching where we are interested in the data types or structure
171
+
* unnamed variables:
172
+
* it never shadows another variable, can be used many times
173
+
* it can be used when:
174
+
* declaring a local variable (`int _ = q.remove()`)
175
+
* resource specification of a try-with-resources (`try (_ = ScopedContxt.acquire())`)
176
+
* exception parameter in a catch clause (`catch (NumberFormatException _)`)
177
+
* header of an enhanced for loop (`for (int i = 0; _ = sideEffect(); i++)`)
178
+
* header of an enhanced for loop (`for (Order _ : orders)`)
179
+
* lambda parameter (`(int x, int _) -> x + x`, `_ -> "lambda with single parameter"`)
180
+
* unnamed patterns:
181
+
* unnamed pattern is an unconditional pattern which binds nothing
182
+
* we can use it in a nested position of a type pattern or a record pattern
183
+
* `p instanceof Point(_, int y)`
184
+
* `case Point(int x, _)`
185
+
* `p instanceof ColoredPoint(Point _, Color c)`
186
+
* unnamed pattern variables:
187
+
* we can use it in any type pattern
188
+
* `p instanceof Point _`
189
+
* `case Point _`
152
190
* APIs:
153
191
* improve `Thread.sleep(millis, nanos)` to actually perform sleep with sub-millisecond time
154
192
* [`java.net.http.Http Client` is now `AutoCloseable`](https://jdk.java.net/21/release-notes#JDK-8267140) and new methods were added to close/shutdown the connection pool.
0 commit comments