【问题标题】:the method can only set one of public / protected / private该方法只能设置公共/受保护/私有之一
【发布时间】: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


【解决方案1】:

好的,我发现了错误……我在YourConsultant :D 前几行留下了一个孤独的“私人”标签。您的 cmets 很有帮助,尤其是要求提供最小、完整和可验证示例的 cmets

【讨论】:

  • 该死的,它也犯了同样的错误,私下挂了
  • 我也这样做了哈哈
猜你喜欢
  • 1970-01-01
  • 2012-06-02
  • 2012-04-10
  • 2023-04-08
  • 2013-01-02
  • 2011-05-20
相关资源
最近更新 更多