声明变量如下:
private String concatenation;
Run Code Online (Sandbox Code Playgroud)
会System.out.println(concatenation)显示这个:
null
Run Code Online (Sandbox Code Playgroud)
这将是一个长度为4的字符串,而不是null(在null或中的布尔类型!null)值.如果我开始研究它会有意义… = "null";,但我没有.
但如果它被声明为:
private String concatenation = "";
Run Code Online (Sandbox Code Playgroud)
然后,System.out.println(concatenation)会显示:
` ` // No clue how to get a space to show up in SO so I am surrounding it with ticks
Run Code Online (Sandbox Code Playgroud)
为什么Java不只是将它创建为具有空字符串的Object,为什么我必须将其定义为空.
java ×1