class TestMe{
public static void main (String args[]){
String s3;
System.out.print(s3);
}
}
为什么编译器报错,refernce 对象的默认值为 null,为什么它不是输出...??
错误:变量 s3 可能尚未初始化
最佳答案
这是一个错误,因为 JLS 在 §14.4.2. Execution of Local Variable Declarations: 中这样说
If a declarator does not have an initialization expression, then every reference to the variable must be preceded by execution of an assignment to the variable, or a compile-time error occurs by the rules of §16.
关于java - 是否需要在 Java 中初始化字符串...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14423035/