[code="java"]public class TestMitiThread1 implements Runnable {
public static void main(String[] args) {
TestMitiThread1 test = new TestMitiThread1();
System.out.println(test); //TestMitiThread1@c17164
Thread thread1 = new Thread(test);
System.out.println(thread1); //Thread[Thread-0,5,main]
}
public void run() {
}
}[/code]
打印对象不应该是引用吗?怎么Thread和另外一个不一样呢?我看Thread.java里面就一个private void init,这是什么原因恩?
TestMitiThread1 test 和 Thread thread1 都不是一种类型,当然打印出来不一样了。Thread打印的结果是它的toString() 方法决定的(这个是java的最基础知识)
[code="java"] public String toString() {
ThreadGroup group = getThreadGroup();
if (group != null) {
return "Thread[" + getName() + "," + getPriority() + "," +
group.getName() + "]";
} else {
return "Thread[" + getName() + "," + getPriority() + "," +
"" + "]";
}
}[/code]
你这个线程似乎都没启动呀,thread1.start()启动线程,你是想要个什么效果呢?
init()是做线程的初始化工作,包括为线程指定线程组、优先级、id等等