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
+48-4Lines changed: 48 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ To run each example use: `java --enable-preview --source 21 <FileName.java>`
27
27
* the main change is remove the support for record pattern in header of an enhanced for loop
28
28
* Pattern matching for `switch`
29
29
* main changes from last JEPs:
30
-
* removed parenthesized patterns (`switch int i when (i > 0)`)
30
+
* removed parenthesized patterns (`case int i when (i > 0)`)
31
31
* allow qualified enum constants as case constants
32
32
* exhaustiveness and compatibility:
33
33
* 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)
@@ -105,9 +105,53 @@ To run each example use: `java --enable-preview --source 21 <FileName.java>`
105
105
* `unmodifiableSequencedCollection`
106
106
* `unmodifiableSequencedSet`
107
107
* `unmodifiableSequencedMap`
108
-
* APIs:
109
-
* improve `Thread.sleep(millis, nanos)` to actually perform sleep with sub-millisecond time
110
-
* [`java.net.http.HttpClient` is now `AutoCloseable`](https://jdk.java.net/21/release-notes#JDK-8267140) and new methods were added to close/shutdown the connection pool.
108
+
* Unnamed classes and instance main methods
109
+
* facilitate the writing of first programm for students without needing to know another features designed for large programs
110
+
* unnamed class:
111
+
* any method declared in a source file without an enclosed class will be considered to be member of an unnamed top-level class
112
+
* the compiler requires an unnamed method to have a valid main method to be launched
113
+
* unnamed class is always final and cannot implement or extends any class other than `Object`
114
+
* is equivalent to the following usage of anonymous class declaration:
115
+
```java
116
+
new Object() {
117
+
void main() {}
118
+
}.main();
119
+
```
120
+
* as it doesn't have a name, so we can use its static methods like `ClassName.staticMethodName()`
121
+
* it still will have the impliticy `this` reference
122
+
* it can have:
123
+
* instance and static methods
124
+
* instance and static fields
125
+
* instance and static initializers
126
+
* the default modifers are the same (package access and instance membership)
127
+
* the main difference is will only have an impliticy default zero-paramater constructor
128
+
* `Class.isSynthetic` method returns true
129
+
* this JEPs introduces changes to how Java programs are launched:
130
+
* instance main method:
131
+
* the class must have a non-private zero-paramater constructor
132
+
* the main method doesn't need to be static, public nor have parameter
133
+
* example:
134
+
```java
135
+
class HelloWord {
136
+
void main() {
137
+
System.out.println("Hello World!");
138
+
}
139
+
}
140
+
```
141
+
* allowing unnamed class:
142
+
```java
143
+
void main() {
144
+
System.out.println("Hello World!");
145
+
}
146
+
```
147
+
* order to select a main method (all must be non-private and it prioritize the methods in current class before the superclass):
148
+
* `static void main(String[])`
149
+
* `static void main()`
150
+
* `void main(String[])`
151
+
* `void main()`
152
+
* APIs:
153
+
* improve `Thread.sleep(millis, nanos)` to actually perform sleep with sub-millisecond time
154
+
* [`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