java – println(String s)vs println(Object o)
•
Java
In my opinion, printstream Print (object x) and printstream Println (object x) and printstream Print (string x) and printstream Println (string x) is the same
Are there obvious reasons for both? Are they any different? Readability of API docs? Efficiency?
(using auto packing, I suspect that even printing methods with primitives as parameters are redundant... But these methods are earlier than the auto packing function, so they can be explained.)
Solution
They don't do the same thing:
Print (object x) calls string Valueof (x), return:
(obj == null) ? "null" : obj.toString();
So we have an extra toString () method
The result is the same because string Tostring() returns this However, in order to facilitate the use of API, users should not be forced to understand these details
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
二维码