javainterfacejava-9

Default access modifier for interface methods in Java 9?


Java 9 allows us to have private methods in interface, which means that not explicitly marking public methods is no longer superfluous.

However, is it now mandatory to do so? I hope the specification still assumes public abstract as the default modifier for methods to maintain backward compatibility with earlier source code?


Solution

  • The Java 9 Language Specification says in §9.4::

    A method in the body of an interface may be declared public or private (§6.6). If no access modifier is given, the method is implicitly public. It is permitted, but discouraged as a matter of style, to redundantly specify the public modifier for a method declaration in an interface.

    Unfortunately, I can't find a link that does not lead to a PDF, diffing the old and new JLS.