JEP 495: Simple Source Files and Instance Main Methods (Fourth Preview)
Mainly for education but also for writing simple scripts
🔹 What JEP 495 Introduces
Simple source file execution: Java can now run
.java
files without compiling them first, even if they're in a package or use preview features.Instance
main()
methods: You can now define themain()
method as an instance method, not just static.
RUN:
JustSimpleSourceDemo
To see that instance method main will be run - it doesn't have to be static anymore.
RUN:
cd src/main/java/com/wlodar/jeeps/jep495simplesourcefiles/
java --enable-preview JustSimpleSourceDemo.java
-> This is an instance method without args not static and you can run it in IDEA
To see that you can run simple java programs
RUN:
java --enable-preview TheSimplestExampleWithJustMainFunction.java
-> As simple as that
the file is just :
public void main() {
println("As simple as that");
}
PreviousJEP 494: Module Import Declarations (Second Preview)NextJEP 496: Quantum-Resistant Module-Lattice-Based Key Encapsulation Mechanism
Last updated