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

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

    Static methods aren't virtual like instance methods so I suppose the Java designers decided they didn't want them in interfaces.

    But you can put classes containing static methods inside interfaces. You could try that!

    public interface Test {
        static class Inner {
            public static Object get() {
                return 0;
            }
        }
    }
    

提交回复
热议问题