Why the out put of below code is Thread[main,5,mai

2019-03-06 18:44发布

public class test1 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Thread t = Thread.currentThread();
        System.out.println(t);
    }
}

Why the output of above code is - Thread[main,5,main] ? Please Explain

3条回答
淡お忘
2楼-- · 2019-03-06 18:53

Because thread.toString() returns a string representation of this thread, including the thread's name, priority, and thread group.

查看更多
叼着烟拽天下
3楼-- · 2019-03-06 19:00

Because of:

/**
 * Returns a string representation of this thread, including the
 * thread's name, priority, and thread group.
 *
 * @return  a string representation of this thread.
 */
public String toString() {
    ThreadGroup group = getThreadGroup();
    if (group != null) {
        return "Thread[" + getName() + "," + getPriority() + "," +
                       group.getName() + "]";
    } else {
        return "Thread[" + getName() + "," + getPriority() + "," +
                        "" + "]";
    }
}
查看更多
爷的心禁止访问
4楼-- · 2019-03-06 19:01

Returns a string representation of this thread, including the thread's name, priority, and thread group.

Source: https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#toString()

查看更多
登录 后发表回答