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

后端 未结 24 1505
没有蜡笔的小新
没有蜡笔的小新 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:33

    Interfaces just provide a list of things a class will provide, not an actual implementation of those things, which is what your static item is.

    If you want statics, use an abstract class and inherit it, otherwise, remove the static.

    Hope that helps!

提交回复
热议问题