代码:
String str="hello";
System.out.println(str);
jdk源码跟踪:
1.println()方法源码
public void println(Object x) {
String s = String.valueOf(x);//这个valueOf()方法里调用了toString()方法
synchronized (this) {
print(s);
newLine();
}
}
2.valueOf()方法源码
public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();//调用了对象的toString()方法
}