Java: Abstract interfaces and abstract interface methods

You may have noticed that it’s possible to mark interfaces and interface methods as abstract. This is completely redundant and in fact discouraged.

public abstractNeither this… interface Printable {




    …nor this, makes any differenceabstract void print();



}

JLS states the following:

Every interface is implicitly abstract.

This modifier is obsolete and should not be used in new programs. JLS §9.1.1.1

and

An interface method lacking a default modifier or a static modifier is implicitly abstract, so its body is represented by a semicolon, not a block. It is permitted, but discouraged as a matter of style, to redundantly specify the abstract modifier for such a method declaration.JLS §9.4

So why is it allowed?

This is a good question. Even the first edition of JLS says

This modifier is obsolete and should not be used in new Java programs. JLS, First Edition, §9.1.2.1

To look even further back in time we need to refer to the Oak language which is the predecessor of Java. And indeed the original Oak 0.2 spec in Section 5, Interfaces has the following example

public interface Storing {
    void freezeDry(Stream s) = 0;
    void reconstitute(Stream s) = 0;
}

And in the margin it says

In the future, the “=0” part of declaring methods in interfaces may go away.

Assuming =0 got replaced by the abstract keyword, abstract was presumably mandatory in some prehistoric version of Java.

Comments