代码尽可能简单,但我似乎遇到了编译器错误。我错过了什么?
作为旁注,_name
完全删除该字段只会在下一个字段上生成相同的错误。
PS:预计会有不少负票,感觉就像我错过了一些非常非常简单的东西。
package mkumpan.helpers;
public final class BotState
{
private final String _name;
private final double _x;
private final double _y;
private final double _energy;
private final double _heading;
private final double _velocity;
public BotState(
String name,
double x,
double y,
double energy,
double heading,
double velocity
) {
String _name = name;
double _x = x;
double _y = y;
double _energy = energy;
double _heading = heading;
double _velocity = velocity;
} // BotState.java:26: error: variable _name might not have been initialized
public String getName() { return _name; }
public double getX() { return _x; }
public double getY() { return _y; }
public double getEnergy() { return _energy; }
public double getHeading() { return _heading; }
public double getVelocity() { return _velocity; }
}