自己去看println方法的实现即可public void print(String s) { if (s == null) { s = "null"; } write(s);
public void print(String s) { if (s == null) { s = "null"; } write(s); 高
String比较特殊,它本身也是个对象。lz可以查查源码 /** * Print a string. If the argument is <code>null</code> then the string * <code>"null"</code> is printed. Otherwise, the string's characters are * converted into bytes according to the platform's default character * encoding, and these bytes are written in exactly the manner of the * <code>{@link #write(int)}</code> method. * * @param s The <code>String</code> to be printed */ public void print(String s) { if (s == null) { s = "null"; } write(s); }
System.out.println(s)
会把s转化成字符串
if (s == null) {
s = "null";
}
write(s);
public void print(String s) {
if (s == null) {
s = "null";
}
write(s);
高
* Print a string. If the argument is <code>null</code> then the string
* <code>"null"</code> is printed. Otherwise, the string's characters are
* converted into bytes according to the platform's default character
* encoding, and these bytes are written in exactly the manner of the
* <code>{@link #write(int)}</code> method.
*
* @param s The <code>String</code> to be printed
*/
public void print(String s) {
if (s == null) {
s = "null";
}
write(s);
}
而且s的初始化的值是null;所以直觉输出s也就是一个null,
再加上s是指向一个空对象。那么它输入的还是null
boolean answer=false;
if(s=="null"){
answer=true;
}
System.out.print(answer);楼主可以看看这个思考思考,,