简体   繁体   English

该方法只能设置public / protected / private之一

[英]the method can only set one of public / protected / private

I'm implementing an interface: 我正在实现一个接口:

public interface Consultant {
    // some documentation here explaining it should throw 3 types of exceptions
    CellLocation suggest(GameBoard gameBoard);
}

It uses another interface: 它使用另一个接口:

public interface GameBoard {
    CellState getCellState(CellLocation cellLocation);
}

I wrote a lot of methods, but just started implementing the all-important suggest method. 我写了很多方法,但刚开始实现了所有重要的建议方法。 It looks like this so far: 到目前为止看起来像这样:

public class YourConsultant implements Consultant {
    @Override
    public CellLocation suggest(GameBoard gameBoard) {
        char[][] arrayBoardGlobal;
        Player currentPlayerGlobal;
        GameState gameStateGlobal;
        return null;
    }
}

But I get the error 但是我得到了错误

The method suggest in type YourConsultant can only set one of public / protected / private 方法建议在类型YourConsultant中只能设置public / protected / private之一

Of course I cannot change it from public to anything else because of the interface. 当然,由于界面的原因,我无法将其从公共更改为其他任何内容。

What could be the cause? 可能是什么原因? I haven't found the answer here or the net, probably because it brings up basic info about access modifiers. 我没有在这里或网上找到答案,可能是因为它提供了有关访问修饰符的基本信息。 I'm using Eclipse Neon. 我正在使用Eclipse Neon。

Okay, I found the error... I left a lonely "private" tag hanging in the air a few lines before YourConsultant :D. 好吧,我发现了错误......在YourConsultant:D之前,我在悬空中留下了一个孤独的“私人”标签。 Your comments were helpful, especially the one asking for a Minimal, Complete and Verifiable example 您的评论很有帮助,尤其是要求提供最小,完整和可验证示例的评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 main()方法可以指定为private还是protected? - Can the main( ) method be specified as private or protected? OOP-谁可以访问公共,私有,受保护的变量? - OOP - Who can access to public, private, protected variable? 在一种公共方法中使用相同的私有方法 - Same private methods to be used in one public method 为什么只有使用 static 方法的 class 会出现错误:“Add a private constructor to hide the implicit public one.”? - Why does only the class with the static method have the error: “Add a private constructor to hide the implicit public one.”? 为什么我可以用公共方法覆盖受保护的方法? - Why can I override a protected method with public method? 公共方法如何返回私有类型? - How can a public method return a private type? 我怎样才能只获得java类的受保护的公共构造函数? - How can I get only protected and public constructors of a java class? 如何在非公共类中测试方法? 我认为在公共类中测试私有或受保护的方法是不一样的 - How to test a method in non-public class ? I think it's NOT the same to test the private or protected method in a public class 没有声明为 public、private 或 protected 的变量是什么? - What are variables without public, private or protected declared as? Java OOP Public vs Private vs Protected - Java OOP Public vs Private vs Protected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM