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

后端 未结 3 1363
迷失自我
迷失自我 2021-01-17 08:54
public class test1 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Thread t = Thread.currentThread();
        Syste         


        
相关标签:
3条回答
  • 2021-01-17 09:14

    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() + "," +
                            "" + "]";
        }
    }
    
    0 讨论(0)
  • 2021-01-17 09:23

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

    0 讨论(0)
  • 2021-01-17 09:24

    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()

    0 讨论(0)
提交回复
热议问题