String.java
怎样将helloworld变量赋值给了String类中的value参数的?
/**
* Returns {@code true} if, and only if, {@link #length()} is {@code 0}.
*
* @return {@code true} if {@link #length()} is {@code 0}, otherwise
* {@code false}
*
* @since 1.6
*/
public boolean isEmpty() {
return value.length == 0;
}
这个value怎样获取到声明的helloworld的?
在什么时候?
前面几位答主都没理解题主的意思。
你一定见过这种
Integer a = 1;
这个是自动装箱。https://docs.oracle.com/javas...
而对应String,文档并没有准确提及编译器到底是如何将字符串变成String对象的。
https://docs.oracle.com/javas...
我猜测这也是自动装箱原理。
String a = "helloworld";
相当于
String a = new String({'h','e','l','l','o','w','o','r','l','d'});
"helloworld".isEmpty();
相当于
new String({'h','e','l','l','o','w','o','r','l','d'}).isEmpty();