版权声明:本文首发 http://asing1elife.com ,转载请注明出处。 https://blog.csdn.net/asing1elife/article/details/83104324
针对每次赋值,创造一个独立、对应的临时变量
更多精彩
- 更多技术博客,请移步 asing1elife’s blog
动机
- 同一个临时变量承担两件不同的事情,会让代码阅读者无法理解
- 循环变量和结果收集变量最容易产生被多次赋值的可能
案例
double temp = 2 * (height * width);
System.out.println(temp);
temp = height * width;
System.out.println(temp);
double temp = 2 * (height * width);
System.out.println(temp);
double area = height * width;
System.out.println(area);