【发布时间】:2017-01-20 23:53:20
【问题描述】:
我正在实现一个接口:
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);
}
我写了很多方法,但刚刚开始实现最重要的建议方法。到目前为止看起来像这样:
public class YourConsultant implements Consultant {
@Override
public CellLocation suggest(GameBoard gameBoard) {
char[][] arrayBoardGlobal;
Player currentPlayerGlobal;
GameState gameStateGlobal;
return null;
}
}
但我得到了错误
YourConsultant 类型中建议的方法只能设置 public/protected/private 之一
当然,由于界面的原因,我不能将其从公开更改为其他任何内容。
可能是什么原因?我在这里或网络上都没有找到答案,可能是因为它提供了有关访问修饰符的基本信息。我正在使用 Eclipse Neon。
【问题讨论】:
-
我强烈怀疑周围的环境有问题。请发帖minimal reproducible example。
-
@Override注释是错误的,因为使用接口您不会覆盖事物。我怀疑你在某处有一个class,它有一个默认为受保护的suggest(GameBoard gb),但我们确实需要查看更多代码来回答这个问题。 -
找到了这个:bugs.eclipse.org/bugs/show_bug.cgi?id=130117。你用的是哪个jdk?
-
@Override注释很可能是错误的。我是这样得到代码的。我希望这不是错误,因为我不知道如何解决问题:) 好的,我会举个例子,但这需要一些时间。 -
@mroman,从 JDK 1.6 及更高版本开始,实际上支持(并鼓励)使用
@Override注释接口方法实现。但我同意原因很可能在YourConsultant的周围代码中。
标签: java eclipse compiler-errors