Constructor for an empty class construct

I was wondering what the argument is about the existence of an empty constructor in the Thread class.

Since you cannot give it Runnable when you create it, create a Thread as follows:

Thread t=new Thread();

Useless.

Can you think of a reason why there is no way to add runnable to the stream AFTER CREATION?

+5
source share
3 answers

The following works:

new Thread() {
    public void run() {
         System.out.println("Well you can change the run method.");
    }

}

but yes, this is not what I consider good practice.

+3
source

You can override the class Thread. Then your own implementation could do something sensible in the method run()without the need for Runnable.

+7
source

Threada class can be subclassed, but run()redefined. See Javadoc .

+1
source

All Articles