我正在实现一个接口:
public interface Consultant {
// some documentation here explaining it should throw 3 types of exceptions
CellLocation suggest(GameBoard gameBoard);
}
它使用另一个接口:
public interface GameBoard {
CellState getCellState(CellLocation cellLocation);
}
我写了很多方法,但刚刚开始实现非常重要的 suggest 方法。到目前为止,它看起来是这样的:
public class YourConsultant implements Consultant {
@Override
public CellLocation suggest(GameBoard gameBoard) {
char[][] arrayBoardGlobal;
Player currentPlayerGlobal;
GameState gameStateGlobal;
return null;
}
}
但我遇到了错误
在YourConsultant类型中建议的方法只能设置public / protected / private中的一个
当然,由于接口的原因,我不能将其从public更改为其他任何内容。
可能是什么原因呢? 我在这里或网络上没有找到答案,可能是因为它涉及访问修饰符的基本信息。我正在使用Eclipse Neon。
suggest(GameBoard gb)
方法,默认情况下是受保护的,但我们确实需要看更多的代码才能回答这个问题。 - mroman@Override
注释是错误的。 我是这样得到代码的。希望这不是一个错误,因为我不知道如何解决 :)好的,我会做一个例子,但这需要一些时间。 - GregT@Override
是被支持(并且鼓励)的。但我同意问题可能出在YourConsultant
周围的代码中。 - E-Riz