6.6 Split Temporary Variable 分解临时变量

版权声明:本文首发 http://asing1elife.com ,转载请注明出处。 https://blog.csdn.net/asing1elife/article/details/83104324

针对每次赋值,创造一个独立、对应的临时变量

更多精彩

动机

  1. 同一个临时变量承担两件不同的事情,会让代码阅读者无法理解
  2. 循环变量和结果收集变量最容易产生被多次赋值的可能

案例

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);

猜你喜欢

转载自blog.csdn.net/asing1elife/article/details/83104324
6.6