Why can't I define a static method in a Java interface?

后端 未结 24 1098
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 05:44

EDIT: As of Java 8, static methods are now allowed in interfaces.

Here\'s the example:

public interface IXMLizable         


        
24条回答
  •  终归单人心
    2020-11-22 06:35

    Well, without generics, static interfaces are useless because all static method calls are resolved at compile time. So, there's no real use for them.

    With generics, they have use -- with or without a default implementation. Obviously there would need to be overriding and so on. However, my guess is that such usage wasn't very OO (as the other answers point out obtusely) and hence wasn't considered worth the effort they'd require to implement usefully.

提交回复
热议问题