Skip to content

Commit 5452fa0

Browse files
committed
JEP 495: Simple Source Files and Instance Main Methods (Fourth Preview)
1 parent 5ea406f commit 5452fa0

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This repository contains Java examples that are designed to track and document t
1111

1212
* [Java 24](java-24/) (March, 2025)
1313
* [JEP 488](java-24/src/main/java/com/ibrahimatay/JEP488PrimitiveTypesInPatternsInstanceofAndSwitch.java): Primitive Types in Patterns, instanceof, and switch
14+
* [JEP 495](java-24/src/main/java/com/ibrahimatay/JEP495SimpleSourceFilesAndInstanceMainMethods.java): Simple Source Files and Instance Main Methods
1415

1516
* [Java 23](java-23/) (September, 2024)
1617
* [JEP 455](java-23/src/main/java/com/ibrahimatay/JEP455PrimitiveTypesInPatternsInstanceofAndSwitch.java): Primitive Types in Patterns, instanceof, and switch
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
public class JEP492FlexibleConstructorBodies {
22
public static void main(String[] args) {
3+
// JEP 492: Flexible Constructor Bodies (Third Preview)
4+
// https://openjdk.org/jeps/492
5+
36

47
}
58
}
9+
record OuterRecord(int outerValue) {
10+
class Inner {
11+
int innerValue;
12+
13+
Inner(OuterRecord OuterRecord.this, int innerValue) {
14+
this.innerValue = innerValue;
15+
System.out.println("OuterRecord Value: " + this);
16+
}
17+
}
18+
}
19+
20+
class EventHandler {
21+
interface Listener {
22+
void onEvent();
23+
}
24+
25+
class ButtonClickListener implements Listener {
26+
ButtonClickListener(EventHandler EventHandler.this) { // Flexible Constructor
27+
System.out.println("Event handler created!");
28+
}
29+
30+
@Override
31+
public void onEvent() {
32+
System.out.println("Button clicked!");
33+
}
34+
}
35+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// JEP 495: Simple Source Files and Instance Main Methods (Fourth Preview)
2+
// https://openjdk.org/jeps/495
3+
4+
public void main() {
5+
System.out.printf("%1$s + %2$s = %3$s", 1,2, sum(1,2));
6+
}
7+
8+
int sum(int x, int y) {
9+
return x+y;
10+
}

0 commit comments

Comments
 (0)