你有一个字面数值(literal number),带有特殊含义.
创造一个常量,根据其意义为它命名,并将上述的字面数值替换为这个常量.
double potentialEnergy(double mass, double height) {
return mass * 9.81 * height;
}
double potentialEnergy(double mass, double height) {
return mass * GRAVITATIONAL_CONSTANT * height;
}
static final double GRAVITATIONAL_CONSTANT = 9.81;