- This allows you to check the main method
- Allows calling the main method from other classes
- This allows you to call the main method several times, while type initialization occurs only once.
- This allows you to instantiate a class containing the main method without running the program.
The idea of initializing the type to lock the "main" class before the application terminates is disgusting.
Can we handle this? I dare say. But I suspect that I will always write:
public class EntryPoint { static { // Workaround for entry points being static initializers String[] arguments = getArgumentsHoweverThatHappens(); RealEntryPoint.execute(arguments); } }
... and nothing else will touch EntryPoint .
Jon skeet
source share