I was wondering what's the reasoning of the existance of an empty constructor on Thread class.
Since you cant give it a Runnable when it's created, creating a Thread like this:
Thread t=new Thread();
Is completely useless.
Can you think of a reason why there is not an option of adding a runnable to a thread AFTER CREATION?
You can override the Thread
class, too. Your own implementation could then do something sensible in the run()
method without the need for a Runnable
.
The following works:
new Thread() {
public void run() {
System.out.println("Well you can change the run method.");
}
}
but yes that's not what I'd consider good practice.
Thread
class can be subclassed, and it's run()
overriden. See the Javadoc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With