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?

+3


source to share


1 answer


The Java 9 Language Specification says in ยง9.4 ::

A method in the body of an interface can either be declared public

or private

(ยง6.6). If no access modifier is specified, the method is implicit public

. It is allowed, but not recommended as a style, to excessively specify a modifier public

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 .

+8


source







All Articles