Java 很2的题
public class HelloWorld {
public static void main(String args[]) {
String s = null;
s = s+"word";
System.out.println("hello " +s);
}
}
试问:输出结果?
hello nullword
解释:
s = s+"word"; 等价于 s = String.valueOf(s)+"word"; Integer,Double都一样。
String的源码:
public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();
}