当我执行下面的代码时,输出是“nullHelloWorld”。 Java如何处理null?为什么空值出现在字符串输出中?
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
String str=null;
str+="Hello World";
System.out.println(str);
}
}
运行代码;-) –
+1:滥用字符串连接规则:)我不知道。 –