Default access modifier for interface methods in Java 9?
Java 9 allows us to have methods private
in an interface, which means explicitly labeling methods is public
no longer redundant.
However, is it now necessary? I hope the spec still assumes public abstract
as the default modifier for methods to maintain backward compatibility with earlier source code?
source to share
The Java 9 Language Specification says in ยง9.4 ::
A method in the body of an interface can either be declared
public
orprivate
(ยง6.6). If no access modifier is specified, the method is implicitpublic
. It is allowed, but not recommended as a style, to excessively specify a modifierpublic
for a method declaration in an interface.
Unfortunately, I cannot find a link that does not result in a PDF different from the old and new JLS .
source to share