相关疑难解决方法(0)

为什么类型为String的空变量声明为"null"而不是""(空白或空)

声明变量如下:

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
推荐指数
1
解决办法
4628
查看次数

标签 统计

java ×1