Roedy Green < > wrote:
> I probably never occurs to most people to initialise static variables
> in main. After all, they are all automatically initialised to 0 or to
> the values in the declarations.
>
> All works fine if you run your program only from the command line. But
> if someone starts automating, and calls your main repeatedly from
> Java, the second calls will get whatever static values were left over
> from the first invocation of main.
If you call main method programmatically, you get what you get. Since
part of the contract of main is that it's called from a fresh JVM and
the process terminates when it's done. You violate the contract, and
there's no reason to expect your code to do anything in particular.
If you really want to make a program runnable programmatically as well
as an app, create a new method that's NOT main, and document its usage
in the normal way. Call it from main. Far less confusing.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation