DESKTOP-F6K5GEP_20200907-崔婧涓
一、问题
Container c = new Container();
c.add( '\u0041' );
System.out.println( c );
System.out.println( c.toString());
这两行输出代码的输出效果为什么是一样的?
解决
System.out.println( c );中println的源代码是这样写的
public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();
}
所以当c不为null时,输出的是c.toString();
二、吐槽
今天天气好热呀,都不用穿外套了。
点赞