Java – can I restart my application using main()?
•
Java
I'm working on a way to restart my java application by clicking a button on the GUI I searched the Internet and encountered main (new string [0]) I need to know if this is an effective way to restart my application Someone can suggest. Thank you
private void bnNewsaleActionPerformed(java.awt.event.ActionEvent evt) { main( new String[0]); }
Would this be better?
private void bnNewsaleActionPerformed(java.awt.event.ActionEvent evt) { classname.this.dispose(); main( new String[0]); }
Solution
It uses an empty string array to call the static main method See if this is clearer:
String[] args = new String[0]; // Or String[] args = {}; main(args);
Admittedly, it is not common to call the main method from a non - main method... This does not really "restart" the application It will call it from your existing handler, which can have dislike consequences. I don't recommend it
If you can find a way to start a completely clean process, it will be a more reliable "restart"
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码