所有的这些转化的前提都是在 转化的目标串都已经实现了 toString方法。 String.valueOf() 也是 源码如下 : /////////////////////// /** * Returns the string representation of the <code>Object</code> argument. * * @param obj an <code>Object</code>. * @return if the argument is <code>null</code>, then a string equal to * <code>"null"</code>; otherwise, the value of * <code>obj.toString()</code> is returned. * @see java.lang.Object#toString() */ public static String valueOf(Object obj) { return (obj == null) ? "null" : obj.toString(); } ///////////////////////基本类型时是 在String.valueOf 时作了转化的。 而且其他的类,要么是自己已经实现了toString方法,要么是程序员自己实现它。 否则你只能都看到 xxxx@xxxxx
String.valueOf() 也是
源码如下 :
///////////////////////
/**
* Returns the string representation of the <code>Object</code> argument.
*
* @param obj an <code>Object</code>.
* @return if the argument is <code>null</code>, then a string equal to
* <code>"null"</code>; otherwise, the value of
* <code>obj.toString()</code> is returned.
* @see java.lang.Object#toString()
*/
public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();
}
///////////////////////基本类型时是 在String.valueOf 时作了转化的。
而且其他的类,要么是自己已经实现了toString方法,要么是程序员自己实现它。
否则你只能都看到 xxxx@xxxxx
用char的数组算不??