Reputation: 922
I have a class that implements Runnable, but Eclipse needs a public static void main method in it. Is it ok if the main is completly empty?
public class Launcher implements Runnable{
private String message;
public Launcher(String message) {
this.message= message;
}
public static void main(String[] args) {
}
@Override
public void run() {
//My implementations
}
Upvotes: 2
Views: 4164
Reputation: 26185
If you intend Launcher
to be the main class of the application, the one you use to start it, the main method is needed and must do whatever should be done to start work.
If not, delete the main method. Eclipse does not require a main method unless you start the application by telling it to run the class. It will optionally generate one when creating a class, but that can be edited out if not needed.
Upvotes: 4
Reputation: 2950
No, the main
method is the only method the compiler is searching for when looking where to start. Hence if you're main
method is empty, nothing gets executed. At the very least add:
new Launcher("some string").run();
in the main method.
Upvotes: 2