Java – why is setname in the thread class assigned to a character array? Why not a string?

When I deal with the thread concept in Java, I have seen thread Java source file I noticed that the setname () method assigns a string to a character array named "name []" Java has the property of string data type, so why do they use character arrays

In the source file, it is initialized to,

private char name[]; // why not "private String name;"

In the setname() method,

public final void setName(String name) {
    checkAccess();
    this.name = name.tocharArray();
    }

Please help me Thank you in advance

Solution

This name is accessed from native code, so it is easier to handle char arrays than mangle with Java type The core lib devs mailing list discussed this issue not long ago, which is a link from the subject to an email The initial problem shows that "a considerable amount of time goes into the thread.setname call. I think a large part of it is for new char allocation and copying char array" Quote answer:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>