Why `private static` field is not allowed in Java 8 interface?

后端 未结 5 1970
野的像风
野的像风 2021-01-11 11:42

When I\'m trying to compile the following code

public interface SomeInterface{
    private static Logger logger = Logger.getLogger();

    public default voi         


        
5条回答
  •  粉色の甜心
    2021-01-11 12:35

    Interface is like a blueprint of any class, where you declare your members. Any class that implement that interface is responsible for its definition. Private members can only be accessed by same class member, which does not make sense in terms of interface. Protected members can be accessed by same class member and inherited class members, but in case of interface we never extend an interface, we implement it. So any interface can only contain public methods generally,

提交回复
热议问题