In the code below, the Java compiler gives me an error in the line calling hasAdditionalLiberty, saying that x0 and y0 "may have not been initialized". I do understand the intent of making this an error, but isn't that in this case, x0 and y0 must be initialized because they always go through the for loop?
So what exactly is the rule deciding the uninitialized variable error?
int x0;
int y0;
for (int i = 0; i < 4; ++i) {
x0 = x + deltaX[i];
y0 = y + deltaY[i];
if (isOnBoard(x0, y0) && at(x0, y0) == Color.Empty) {
break;
}
}
if (!hasAdditionalLiberty(x, y, x0, y0)) {
koX = x0;
koY = y0;
}
for (int i=0; i < 4; ++i) {andfor (int i=0; i > 4; ++i) {, for example.