Java tutorial says I can have a package-private interface, but I can't

后端 未结 3 992
太阳男子
太阳男子 2020-12-13 13:19

In the Java tutorial \"Defining an Interface\", it says

If you do not specify that the interface is public, your interface will be acces

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 14:14

    I think (though I could be wrong about this) that the weaker access privileges being discussed here are for the foo() and bar() methods in NewClass. All interface methods are implicitly public, but in NewClass you've left them package-private, which is a weaker guarantee than public. Changing NewClass to read

    class NewClass implements PPInterface{
        public void foo() {}
        public void bar() {}
    }
    

    probably will fix this.

提交回复
热议问题