问题
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?
回答1:
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.
回答2:
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
.
回答3:
Thread
class can be subclassed, and it's run()
overriden. See the Javadoc.
来源:https://stackoverflow.com/questions/9244147/thread-class-empty-constructor