Why can’t I declare static methods in an interface?

There are a few issues at play here. The first is the issue of declaring a static method without defining it. This is the difference between

public interface Foo {
  public static int bar();
}

and

public interface Foo {
  public static int bar() {
    ...
  }
}

The first is impossible for the reasons that Espo mentions: you don’t know which implementing class is the correct definition.

Java could allow the latter; and in fact, starting in Java 8, it does!

Leave a Comment