In Thread.java, line 146, I have noticed that the author used a char[] instead of a String for the name field. Are there any performance reasons that I am not aware of? getName() also wraps the character in a String before returning the name. Isn’t it better to just use a String?
In Thread.java , line 146, I have noticed that the author used a char[]
Share
In general, yes. I suspect
char[]was used inThreadfor performance reasons, back in the days when such things in Java required every effort to get decent performance. With the advent of modern JVMs, such micro-optimizations have long since become unimportant, but it’s just been left that way.There’s a lot of weird code in the old Java 1.0-era source, I wouldn’t pay too much attention to it.