Skip to content

Commit 0fee16c

Browse files
committed
Added Java "Unnamed Classes and Instance Main Methods" example.
1 parent b2c7dca commit 0fee16c

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

build-logic/src/main/kotlin/org.sdkotlin.buildlogic.kotlin-project.gradle.kts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ dependencies {
2121

2222
tasks {
2323

24-
withType<JavaCompile>().configureEach {
25-
with(options) {
26-
release = javaTargetVersion.toInt()
27-
isFork = true
28-
}
29-
}
30-
3124
withType<KotlinCompile>().configureEach {
3225
compilerOptions {
3326
optIn.addAll(
@@ -44,4 +37,20 @@ tasks {
4437
)
4538
}
4639
}
40+
41+
withType<JavaCompile>().configureEach {
42+
with(options) {
43+
release = javaTargetVersion.toInt()
44+
compilerArgs.add("--enable-preview")
45+
isFork = true
46+
}
47+
}
48+
49+
withType<Test>().configureEach {
50+
jvmArgs("--enable-preview")
51+
}
52+
53+
withType<JavaExec>().configureEach {
54+
jvmArgs("--enable-preview")
55+
}
4756
}

subprojects/kotlin-for-java-devs/src/main/java/org/sdkotlin/intro/java/_00_classes/ClassesInJava.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class ClassesInJava {
77
}
88

99
// You can have multiple classes in a file, but only one public class,
10-
// and curly braces required.
10+
// and curly braces are required.
1111

1212
class Class {
1313

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Java 21+ is previewing "Unnamed Classes and Instance Main Methods":
3+
* <ul>
4+
* <li><a href="https://openjdk.org/jeps/445">JEP 445 (Preview 1, JDK 21)</a></li>
5+
* <li><a href="https://openjdk.org/jeps/463">JEP 463 (Preview 2, JDK 22)</a></li>
6+
* <li><a href="https://openjdk.org/jeps/477">JEP 477 (Preview 3, JDK 23)</a></li>
7+
* <li><a href="https://openjdk.org/jeps/495">JEP 495 (Preview 4, JDK 24)</a></li>
8+
* </ul>
9+
*/
10+
void main() {
11+
System.out.println("Hello World");
12+
}

0 commit comments

Comments
 (0)