alternative to static initialization blocks
I've been asked to modify some code written by someone else. The code currently has a static initialization block that invokes a program and also uses addShutdownHook to exit cleanly. To invoke and close the program you have to pass a file name as an argument. The static block was working perfect here because the user was passing the file name on the command line when he ran the class using the -D option and the name of the variable. They don't want to do that anymore. I won't have the file name until the user invokes a begin(String file) method. So the static initialization is not a good idea anymore. btw, this class doesn't have a main method. Since I'm new to java, I'm not sure which would be the best approach. I read somewhere that a private static method is an alternative to static initialization blocks. Can I create a private static method and move the lines that start and exit the program there and then call it from inside the begin method? :confused:
I will appreciate any help!