今天刚开始自学java,求问一个简单的问题,这个方法为什么不对,错误信息是
Required: Direction(另外一个类?)
found:int
static Direction tileCodeToOrientation(int tileCode) {
int tileIndex = tileCode % 4;
int boardPosition;
if (tileIndex >= 0 && tileIndex<=2){
boardPosition = tileIndex + 6;
}
else if (tileIndex >= 3 && tileIndex<=5){
boardPosition = tileIndex + 8;
}
else if (tileIndex >= 6 && tileIndex<=8){
boardPosition = tileIndex + 10;
}
/* tiles index board board position
col: 3 2 1 row: col: 3 2 1 row:
0 1 2 1 0 1 2 1
3 4 5 2 3 4 5 2
6 7 8 3 6 7 8 3
*/
return boardPosition;
就是想把第一个board上的数字转换成第二个上面的,再输出
个人观点:
上述方法定义返回类型为Direction,但方法返回值是int类型
方法语气返回类型和实际返回类型不匹配,所以报错
希望对你有所帮助,谢谢