你的程序有某個(gè)臨時(shí)變量被賦值超過一次,它既不是循環(huán)變量,也不是一個(gè)集用臨時(shí)變量(collection temporary variable)。
針對(duì)每次賦值,創(chuàng)造一個(gè)獨(dú)立的、對(duì)應(yīng)的臨時(shí)變量。
double temp = 2 * (_height + _widgth);
System.out.println(temp);
temp = _height * _widgth;
System.out.println(temp);
| |
\ /
final double perimeter = 2 * (_height + _widgth);
System.out.println(perimeter);
final double area = _height * _widgth;
System.out.println(area);
針對(duì)每次賦值,創(chuàng)造一個(gè)獨(dú)立的、對(duì)應(yīng)的臨時(shí)變量。
double temp = 2 * (_height + _widgth);
System.out.println(temp);
temp = _height * _widgth;
System.out.println(temp);
| |
\ /
final double perimeter = 2 * (_height + _widgth);
System.out.println(perimeter);
final double area = _height * _widgth;
System.out.println(area);