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

后端 未结 5 1946
野的像风
野的像风 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:22

    Interfaces are not classes. They have no private state. Even a public logger in the interface is a design smell and an abuse of interfaces.

    The use case for static fields in interfaces is mainly for compile-time constants, not for stateful objects.

提交回复
热议问题