为什么以下工作正常?
String str;
while (condition) {
str = calculateStr();
.....
}
Run Code Online (Sandbox Code Playgroud)
但据说这个是危险的/不正确的:
while (condition) {
String str = calculateStr();
.....
}
Run Code Online (Sandbox Code Playgroud)
是否有必要在循环外声明变量?