Why does the following work fine?
String str; while (condition) { str = calculateStr(); ..... }
But this one is said to be dangerou
As many people have pointed out,
String str; while(condition){ str = calculateStr(); ..... }
is NOT better than this:
while(condition){ String str = calculateStr(); ..... }
So don't declare variables outside their scopes if you are not reusing it...