2 ms·
Offtopic, but: Is this not just shorthand, but an actual legitimate Java program these days?
by wwweston 10y ago
Offtopic, but:
Is this not just shorthand, but an actual legitimate Java program these days?
- SpaceManiac 10y agoA bit of both. Code still belongs in a class, not pictured here. `static` blocks are executed when the class is loaded and are usually used to fill `static final` members. In a toy example like this it's shorter than writing the `main()` incantation.
- ezekg 10y agoI was curious as well, so I took it for a spin[0]. In short, no. A static initializer still needs to be wrapped in a class that contains a main method. public class Main { static { System.out.println("Hello world"); } public static void main(String[] args) {} } [0]: https://repl.it/GDZG/1 https://repl.it/GDZG/1